Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
e1 += e2 translates into e1 = (T) (e1 + e2), where T is a type of e1. In this case, the implicit cast crops double into int, which might lead to a not-very-easy-to-find bug:
int num = 1;
double d = 9999999999d;
num += d;
This comment is hidden because it contains spoiler information about the solution
if the str starts with ")" there is no need to continue: the answer is known.
Yeah I thought I speak for myself all the time (didn't I? Who did I speak for from your point of view?)
I had some strange feeling about this kata in the beginning, after executing the java version test as-is I got: ./src/test/java/BagelTest.java:9: error: incompatible types: BagelSolver.Bagel cannot be converted to Bagel
Then I went to the discussion to see whether this is a part of a riddle or an issue. On the discussion page, I again got that bad feeling about it. Then after spending some time dealing with the errors, I looked at the solutions and it confirmed my bad feelings about it. I thought it would be nice to write to others that they might be rather frustrated here, while there are more interesting katas out there.
Good for you that you learned something along the way. But in my opinion this kata has a low ROI: a lot of difficulties to solve and so little as a reward. I believe a lot of people will know a possible solution, but will discard it, because this is something that never exists in good production code. So they would waste quite some time to find another way to solve it. It's like using some anti-pattern such as GOTO, many people know about it, but nobody is going to use it.
I didn't get the point in the second part. Do you think there should be only comments like: wow, that's just the brilliant kata! I got the fantastic error, the task is pleasantly vague, I really enjoyed the time of struggling to understand what the author meant
Speak for yourself. I found it valuable as it forced me to delve into Reflection. I learned something along the way.
Also, as Grandpaw liked to say: "If you ain't got nothin' nice t'say, 'tis better ain't t'say nothin' at all."
Cheers.
This comment is hidden because it contains spoiler information about the solution
I blame YouTube for that.
Hence mob-upvoting the refactoring of a brute force solution into a method that replicates the behavior of native Java, except with higher CPU overhead.
This site offers a wonderful chance to actually learn a new language and use everything it has to offer, but not everyone is willing to take on the challenge.
I say they're missing out, but to each their own.
Best pratices doesn't mean most faster or efficient. Good balance (performance, readability, maintainability) is the key of best pratices: so it includes good readability.
As for why so many people marked it as "Best Practice"... maybe they liked the variable names and spacing between lines?! Just kidding. I'm guessing they just didn't realize there was a better way. Or they exhibited mob behaviour - once it has a few upvotes others upvote to go with the crowd.
@sheriv, it's not one iteration. For each index he's checking he sums up all the numbers on the left and all the numbers on the right. He's forcing the CPU to do the same calculations over and over, and to solve this it's unnecessary. For example if you are at an index and already know the left and right sums at that point, you only need to remove one element and add one element to check the neighbouring index - but the solution above has the program recalculate the entire sum on both sides. It's functional but it's not elegant or efficient.
I think the best solution gives us O(n) complexity since there'is only one iteration.
I don't think that this is as difficult as coming up with a formula of relativity theory. Others have decided that this kata is worth 4 kyu, which means that, yes, it's difficult, but not that difficult. As for the inverse function, it has a precise mathematical definition: If
f
is a function from the non-negative integers to the non-negative integers such thatf
is one-to-one and onto, thenf
has an inverseg
such that iff(x) = y
theng(y) = x
. Since I'm telling you that the mystery function has an inverse, I am implicitely telling you that it is one-to-one and onto.Very strange and weird kata. Basically, this kata tests whether one know what the the mystery function is. Roughly speaking, it is something similar to ask people to write some formulas from the theory of relativity: it's easy when you remember it, and it's highly unlikely that you will be able to come up with a solution in case you haven't studied it.
In addition, there's no explanation what the inversed function should do, as well as there's no examples for this function. How is one supposed to know what 'mysteryInv' means?
Not even easy to read. Just bad solution... ;)
I'm always wondering why people consider solutions like this best practice. Easy to read and understand: Yes. Best practice: Never ever.
Loading more items...