5 kyu
Prime Ant - Performance Version
106anter69
Loading description...
Performance
Algorithms
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Here I thought I was gonna be a 'smart' cookie by doing quick jumps to queued positions, to make it faster. (the distance can be up to tens or hundreds of "steps" from the lowest position)
My solution passes 1 out of 5 times, depending on the inputs.
Think i'll skip the "insane" version, looking at the other solutions i feel a python noob hahaha.
Great Kata though!
I don't understand this kata. Perhaps a couple of sample tests with very low values of
n
to see what we need to return wouldn't hurt. I don't know whether we should return the full sequence A (for 1e6 items) sliced with the correspondingp
forn
or the sequence at the time we reachn
during generation of the seqence.I managed to solve it, but I still think in the sample tests there should be a couple of startup tests with low value of
n
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Should I try to finde a mathematical logic in the final result's list and than apply the formula or should I optimise my algorithme?
No special mathematical tricks are needed, so go for the optimization
You're lying -_-
your python version test isn't explainative enough:
How the user is supposed to understand what the problem is? ;)
=> needs an update of the message. Note that you could put a f-string somewhere, and that would restrict the language versions to 3.6 directly "at the kata level".
cheers
I updated the error message, although it seems that 2.7 is not available in the kata, so it may not even be necessary.
Cheers
The tests may be too tight now, nearly CW-charge dependent. I tried 15 times with my first version, but it finally pass the tests. I already used a sieve and a cache made no difference: still hard to validate a solution. If your purpose is only to invite players to use cache and sieve, may I suggest to lower test requirements? Otherwise, if you want them to make more tricky tweaks, it is fine - but it would be better if you warn players at the end of the description ;-)
As you can read below, earlier I had a problem with too few tests, so "naive" solutions could pass. So I raised the number of tests to make people think a bit. Some of the valid solutions are still "naive" in a way, but they use the right kind of optimization. After all, I planned to make this a performance kata, where you have to consider using e.g. a list vs. a set, or caching some (partial) results, etc. Isn't that optimization?
My reference solution (puzzled from multiple solutions) runs the final tests in about 10000ms (on average), which leaves - I think - a large enough margin for other solutions. But that also means that you won't necessarily succedd with your first try... Probably the ranking should be rather 4kyu instead of 5, to give a hint? But I can't change it :-)
This comment has been hidden.
This comment has been hidden.
I removed the precalculation timer -- now let me see that solution! :-)
Hold your horses! -- I will rather make a "crazy" version of the kata, where you have to do 1000+ tests with big enough numbers :-) And probably change this one a bit too, to have only one HUGE test, instead of many...
Good idea!
Here we go! :-) https://www.codewars.com/kata/prime-ant-crazy-version/
Hi,
maybe you should relax a bit more the tests, don't you think? Look at my solution: it mostly applies what you wanted to get, tho it passed only by chance (11,7s) this morning while it was failing around 254 passed tests yesterday. I guess it's because I append the elements rather than create a whole list right at the beginning, so that sounds a bit too much like an enforced microptimization to me. What's your opinion?
Note: confirmed: when I change that part of the code, I get around 9,5s.
additionnal note: the current top solution is timing out like hell, whatever I try, btw. ;o
Reduced the number of tests by 20% (to 200 + 20). I hope this solves the timeout problems while still excluding the naive solutions.
Cheers
This comment has been hidden.
Thanks for the feedback.
Indeed, the simplest algo shouldn't pass, so I increased the number of tests. Current solutions should now time out, while the reference solution finished under 10s.
Approved :)
Thanks!
Could you open up the Beta to JavaScript? Python's on the docket, but I'm not there yet.
I'm not sure I understand you correctly, but I cannot provide a JS version, until somebody translates it.