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.
Maybe I am a bozo but no need to be rude for posting an issue; instead you should give the input and your output.
I don't understand why try/except would be faster. Can you (or more likely, someone else) explain?
To those defending it based on readability, using += on a String in a loop is both a performance anti-pattern and not more readable than using a StringBuilder with StringBuilder.append in place of += on a String.
This comment is hidden because it contains spoiler information about the solution
The definition of modulo is very ambiguous simply because there are several different accepted definitions. Many call javascript's
%
a modulus operation. Additionally, I wouldn't consider Javascript modulus a true remainder operator, because it takes the sign after division. Historically, remainders have been annotated as non-negative integers. That's why I provided a definition in the description.Yeah, I thought the same thing after I saw this (the c/java part)
thnx m8 =)
I have to agree with SithFire here. It specifically says when you hover over the 'Best Practices' button: "Best Practice solutions tend to be a good balance of performance, readability and maintainability."
It does sounds like you are only focusing on performance in your comment.
Multiplication is still O(n**2), so...
Best practise doesn't mean you have the fastest solution. It's a trade-off among different characteristics of software quality, e.g. time behaviour, changeability, code readability, testability and so on (cf. ISO/IEC 9126). It depends on individual cases. For instance, if this method is called once, this might be the best solution, O(n^2) wouldn't hurt anybody. If this method is called million times, this solution could be a big pain.
I agree there is a difference between short code and quality code. But there is also a difference between performance and quality code. Since you only talked about time behaviour, I think you mistake performance/time behaviour for quality code (= best practise).
Agreeing. Both issues take O(n^2) time, and both operations (checking for multiples vs. single occurrence and appending a result string) are doable in O(n) time.
If indexOf(x) and lastIndexOf(x) cached their values (since String is immutable), the result would be O(n), but that's not how String is coded as of Java 8.
The Java compiler optimizes String x += y to the bytecode equivalent of
However, it does not take the optimization a step further to automatically create a single StringBuffer in a loop. That is, it does NOT perform the optimization
...to...
Prior to doing some research, I thought that's what happened under the covers -- but it's clear that I was wrong.
You can also solve it by initialising it with a seed known to you, saving a random number in guess and then resetting to the seed you chose, at least that seems to be the intention of this Kata.
To elaborate: In Java, I get "Method PeopleThatPlayBanjo() should not be static". Removing the Static keyword from the test case makes it work.
Well, if you think your solution is really good enough, you may employ that "cheating" to pass the last test case, and then compare your solution to the original one to find out what's the difference. Noone would blame you. :)
Definitely yes. :)
The last test is the most complex and the most "real-life" of all.
In fact, if you pass all the tests except the last one, THAT means you employ some kind of cheating :) by tweaking your solution to work with particular tests, instead of making a universal algorithm. :)
The simplified K-means clustering algorithm usable for this kata is just about 40 lines of code, not so much.
Loading more items...