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.
I didn't realize that the print view would expose the test cases. Thanks for that. I opened an issue, but it's to specify that I still think the nominal test cases should complete within a second. https://github.com/Codewars/codewars.com/issues/574
I still think these heavy-duty test runs are putting unnecessary strain on the server.
Half (3.5 seconds) is probably pushing it. It takes very little for the server to drop to half-speed. The problem is that there is no way of telling if it's my code or the server. By the time things recovered, I had already "unlocked solutions" to discover that my code would've been okay.
It would probably be more polite to the CodeWars limited server resources to shoot for within a second.
In any case, I agree that it would've been nice to at least see what test cases were attempted when the failure occurred so that I could run them locally on my laptop and get an inkling if the processing time is reasonable.
Interesting note: Turns out that iterating through a list of previous primes (for k in primes) instead of just doing odd numbers takes a little more time for doing a prime check. Changing that line made the short test finish in about 60ms instead of 100ms, so now it passes in about 3.5 seconds. Even though my old code uses far fewer loops, it apparently takes more time than I expected to start each iteration.
Okay, I'm going to call for comments before I rate this kata, but I'm going to start down-rating every kata that continues this trend of "you must find the upmost optimized solution or it's a fail" with the Python branch.
This Kata is a simple logic problem that was forced to be difficult to "solve" in Python because, let's face it, Python is slower than C. At the time, my solution would run the test in 89 to 120ms, but it fails the 7-second barrier. Granted, I'm not using the "sieve" or "wheel" algorithm to generate the primes (just a basic +2 increment with a modulus to the previous primes), but that shouldn't be neccessary. I don't even get to see what the test cases were, so I have no idea how close I am.
So, I gave up. I unlocked the solutions. I copy & pasted the top solution:
...and it FAILED! Yah, the servers were having a bad day. I tried it later this evening, and this time it passed in 2.5 seconds. It's too late for me because I already unlocked the solutions, but I know better than to blame the servers.
I don't mind a difficult problem, but CodeWars was never designed for code-profiling and evaluating execution times. The time it takes to run the code can vary depending on the server load. Besides, we should be concentrating on solving the problem, not finding the one optimized solution that gets through the server on a good day.
I've endured two other Python Katas like this, and I've decided that they just aren't worth it. I prefer the Katas where it is truly a test of logic. Either you solved the problem, or you didn't. The world rarely cares if you found a way to make the code run 3 seconds faster. If you want to play the optimization game, then clearly label it as such, and make sure you put enough margin in so that solutions still pass on bad server day.
Regardless, this is a bad trend in CodeWars. I'm undecided if I want to recommend this to my sons or not.
The run-time of a solution could be updated when you select "compare with my solution" so that you could at least compare the speed of one solution versus your own. I agree that creating a global score would be challenging. Perhaps they could semi-regularly check run times on the top 10 up-voted solutions.