This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!

Liutauras Vilda

+ Follow
since Nov 12, 2014
Liutauras likes ...
BSD Linux Mac OS X VI Editor
London, United Kingdom
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt Green check
expand Greenhorn Scavenger Hunt

Recent posts by Liutauras Vilda

Michael GrĂ¼nau wrote:I looked for a few possible ways on different websites and tried to adapt some ideas into my program, but I am quite lost and don't know where to continue or what I need to change.

I don't have much time to help now, but could suggest one thing in advance. Delete all that code and start solving it yourself in small steps without any examples took from Internet. That is the main reason probably why you have no idea how to continue.

First, you have lots of duplication which makes your code very hard to understand - mainly for yourself.

Have you learned about object oriented design/approach already?
7 hours ago
Jeanne, Scott - a big congratulations with a book release!
Maybe reminding yourself some definition would help to derive to some conclusion.

"The runtime O(f(n)) means that with the growth of n the runtime of the program grows proportionally to fuction f(n)."

Now in a case of Log2(8) and Log100(1000000), we increased n significantly, but how the answer differed?

Answer questions in the post above and you'll know the answer.
4 days ago

Log2(n) - let's multiply its base few times 2 x 2 x 2 = 8, and so if we had Log2(8) what the answer would be?

Log100(n) - let's multiply again its base few times 100 x 100 x 100 = 1000000, and so if we had Log100(1000000) what the answer would be?
4 days ago

Junilu Lacar wrote:It's all about context though. As long as there's enough to reasonably inform whoever comes into the code without prior knowledge or experience what the abbreviation means, then I'd say abbreviations are fine. I wouldn't go overboard though.

Thankful for the thorough answer. That drew for me a clearer line comparing to what I had in my mind.
4 days ago

Junilu Lacar wrote:If a shorter name expresses the idea just as well, prefer the shorter name.

Does this apply to abbreviations? I personally not a fan of them, but in quite a few cases I can understand what they mean. Do you prefer shorten the names by abbreviating them?
4 days ago

Junilu Lacar wrote:Still not as good as a lookup table (the method Campbell showed earlier)

As far as I know, switch statement is implemented to use loookupswitch or tableswitch operations, which essentially use lookup tables. Which operation in particular to use is decided based on the present cases within the switch statements's block (one can do more research for more details). So from the performance standpoint, lookup time complexity supposed to be as as fast as in arrays if that was one of concerns/reasons to say that switch statement "...isn't as good as lookup table", but knowing Junilu, I presume he addressed more simplicity and clarity of the solution rather than performance.

I actually perhaps would prefer approach with switch over Campbell's proposed arrays solution in OP's given scenario, because it seems OP as a month translation keys have strings, which is easier to handle in switch statement, than to use some parsing constructs and then handle potential exceptions (i.e. ArrayIndexOutOfBoundsException, NumberFormatException). Of course that is doable, and having that Campbell's proposed solution would become quite an elegant.

Now I just saw Piet's suggested yet another approach - that is by far most elegant it seems, just need to handle same aspects of parsing as in Campbell's suggestion.

Depending of course on OP's requirements, whether it is something for college with prescribed instructions what is allowed or what is not, or whether it is something "free to choose", Piet's solution looks very promising.
4 days ago
For quite some time we were very attentive and noticed, that:

Randy Tong, D.J. Quavern and John Damien Smith

have been consistently helpful on the CodeRanch forums. We were so exited, so decided to award them with the Rancher titles.

All, please join us in congratulating them.

The crew of three! Thank you for your contributions to these forums and congratulations on the new titles.

Oh yeah, your herd of cattle is going to expand a little, unfortunately you can't refuse that, so you'll have to take care of them Keep doing the great job!

What does the Rancher title mean?

This page has a brief description about it. Unlike the moderator titles (like Bartender, Sheriffs etc...) which have super powers associated with them, the Rancher title is more a token of appreciation for the members' contributions. However, the one notable power that a Rancher title brings in, is the ability to award cows to fellow members. So whenever you see a post which deserves a cow, please do make use of your powers and award them.f
5 days ago
I just probably used N and M interchanged, so really according to an instructions M represents values in an array, while N represents a number of elements to move. I used them otherway round - but that doesn't change the answer, idea is the same.
6 days ago
So, you have a task to move 3 numbers to the back of an array.

Let's forget that for a moment.

Let's assume you need to take very first number and move it to the end of an array. What the time complexity would be? O(n). Why? That's because you'd need (going to say in simpler words, but not quite exactly what's happening) to take very first value and going step by step starting from the start position to a finish line. Meaning you'd need to go all the distance (array's length) once.

And so think of it you have done it in 5 seconds. So you ran through the distance of n in 5 seconds.

Now, the description says how the algorithm is implemented, "that you take one value at a time...".

So having said that, after you moved 1 element to an end of an array, you need to do the same now with the other first element (it was second in initial setup) - so it takes yet again 5 seconds.

Finally you need to take another first element and move it to the end - yet again 5 seconds.

So you moved 3 elements. m = 3, and n = 5s.

so O(m*n) = 15 s, makes sense, right?

It would be O(n) if you could take all 3 elements at once (check once again in instructions what is said about the used algorithm) and carry them over to the end of an array.
6 days ago
Congratulations to all winners. Thanks for coming Aimee.
6 days ago

error: incompatible types: String cannot be converted to int

"$8.50" isn't an int, it is a string, those quotes (opening and closing) denote that. If you'd take quotes off, you'd get also an error about $ symbol.

Think about ints as about whole numbers. And about doubles as about fractional numbers.

Some examples of ints:
0, 1, 2, 100, -100, -1, ...

Some examples of doubles:
0.3, 8.5, 4.2, ...

So you really want not an int, but double maybe for your exercise. Or if you use ints, then convert the price to cents and then pass that amount, i.e. 850 $ cents = $ 8.5
1 week ago

Dom Pearson wrote:Hello everyone! I am a bit confused about when to use abstract classes vs interfaces. For example, if I need to create a system for education with students and teachers what would be the best way to go about it?

Well, first would be a good idea to define the problem and write down the steps what the system supposed to do.

I need to create a system for education with students and teachers

That's not enough to start coding. You need more than that. But as for example, from that you could infer, that you may need a School, Student and a Teacher classes, that's all you know at this moment in time.

What else system needs to do? i.e. Student should be able to enrol to a Course? Here we go, we also know we may need a Course class. Get an idea? You describe what systems needs to do until you have a pretty big picture of the system (probably not the whole).

Dom Pearson wrote:Should I create a person interface, abstract class for teachers (to be able to create teachers for different subjects) and then a simple class for student?

Or should I make a person an abstract class and teacher interface and then create different teachers? What would be the best way to implement this example if I explicitly need to be able to create multiple teachers? I am quite confused of when to use which.

Too early to discuss that. Once you know about the project to some good extent, you can plan the coding part by seeing what you need. Which parts may be repetitive and could be extracted to abstract classes or interfaces if there is a need at all for that.
1 week ago
Welcome back, Miles.

C, C++, C#, Delphi, Go, Haskell, JavaScript, Kotlin, Lisp, Lua, Perl, PHP, Python, Ruby, Rust, Scratch (teaching my kids...

Don't forget to say a word or two about Ranch to your kids, they seem to be polyglots by now, so we are expecting to onboard their knowledge
1 week ago