4 kyu
Don't give me five! Really!
68 of 459zappa78
Loading description...
Algorithms
Mathematics
Performance
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.
Haskell translation
I really hate this kata. It takes me 2 weeks to complete it.
bomboclaat
no
hold me back
I've got an off-by-one error in SOME test cases with seemingly no consistency. How can I come so far and have this happen? The worst thing is I can pass the 100,000 big numbers but for some reason not the 10,000 big numbers nor the 1000 big numbers.
Edit: It's been 3 weeks, I came back, now I can pass everything EXCEPT 100,000 big numbers.
5 minutes later edit: I DID IT!! My problem was some awkward dealings with start numbers not being inclusive in some certain circumstances. Goddamn longest I've ever spent on a kata but at least it'll stop annoying me that I haven't been able to solve it now. 4500ms too which is pretty good I think?
Tnx all! I'm very enjoy it!
I struggled too solve this and then struggled too make it fast ennough too pass, but very rewarding!
This comment has been hidden.
This comment has been hidden.
i like this and really wonder where is my mistake, it works fine for small and larger numbers but my abstraction for huge numbers just wont match... even when i "manually calculate", my results are way bigger than the expected ones... hope one day i´ll solve this
Go translation
D translation
Rust translation
Lol i just write loop without do anything and it tell me Timed Out (12000 ms)
the faster loop in js :V >> while (start <= end){}
That looks like an infinite loop if start is less than or equal end, it'll run forever.
sorry i forgot to write start++ but also give me timed out by the way i solved the problem but with huge numbers i falied with time
Contrarily to what you are pretending, this loop doesn't do nothing, it increments a value a certain number of times. And this is too slow for this kata, because tested values are very high and there can big huge delta between them.
So is there a solution without using loop ?
You cannot iterate from
start
toend
and just count the numbers that don't contain five, if that's your question. This approach is the one expected in the easy version of the kata, here you must find something more efficient.When I wrote this code, it took a very long time for my solution to come up against the time check. On my laptop, it took about 11 seconds to run 10 million random tests, but on the server, it didn't make it in 12 seconds. I decided to rewrite one function, figuring that the program could potentially speed up by half. As a result, the program ran 100 times faster. The execution time for 10 million tests became about 100,000 milliseconds. On the one hand I'm glad that it worked, but on the other hand I have absolutely no idea what the reason is for this acceleration.
On which language did you do it? I found the algo, but still have some troubles if you passed it on C++ can you please give the code
.
First of all: I absolutely love this kata. On the surface it seems so simple... but its surface conceals many, hidden complexities. Thank you @zappa78!
Unfortunately I also feel something is wrong with the Javascript variant, just like @zhirnov-d and @Iluxmas remarked 4 days and 17 days ago. Perhaps due to an update, as @Iluxmas suggested?
I have written quite a performant algorithm (tests complete in 733ms, that's even about 16 times faster than @Iluxmas), but still I get remote timeouts. While remotely all '10000 big numbers' and all '100000 big numbers' pass, the final category '1000000 big numbers' times out.
I came to believe that something is wrong because of three reasons:
What do you think of this, @zappa78?
I will try to share my solution in a comment to myself, so that I can set a spoiler flag.
This comment has been hidden.
I'll look into that. Just give me few days, I am a bit on a tight schedule at the moment.
Of course, thanks for looking into it!
Let me know if I can be of any help by providing more details.
As a quick first test I ran a few of the most recent accepted solutions and oldest solutions (see below) using Node v14.x (results for other nodes in parentheses). Indeed, some of the recent solutions time out. Maybe they passed with older nodes, but I tested that for only one. The three oldest solutions all pass consistently by a wide margin. There is some significant variation in time for subsequent attempts, possibly connected to server load. I ran these tests on a Saturday afternoon European time.
Conclusion, the kata still works. It is not enough to have just any logarithmic complexity algorithm. Also the code needs to be performance optimised. This is possible: monadius' solution is on average 15% faster than my initial solution.
I hope that helps. Good luck!
recent sollutions:
old solutions:
I haven't solved the kata so I cannot say much. This is a recurring problem with performance katas, they can be closely dependent on the language version and any update can mess it up. This is not fair however, and ideally the tests should be adjusted when a new update creates important performance disparities like apparently here.
Yes, I understand your comment, but this evidently does not apply here, because old solutions still pass in all language versions. An they pass by a wide margin. Less than 9000ms is well below th cut-off
Oh I misread your comment actually. I cannot have a well founded opinion about the issue raised since I have not solved the kata.
I guess that settles this issue...
Hmmm, all test are green and "Completed in 11665ms" but below is written "Execution Timed Out (12000 ms)" :[
Switching to Node v.10 helped
Javascript, all my relatively fast solutions failed due to time out so I gave up and unlocked submitted solutions. To my surprise all approved solutions I checked also timed out. I tried FF and Chrome on Windows and Ununtu machines just to be sure. What might be the problem?
Seems that switching to Node v10 increases speed of some solutions but some solutions still time out
It happens sometimes after an update. This is a recurring problem on certain performance katas. It's hard to be adjusted in random tests because any update can mess it up.
Damn, it was tough but I finally completed it! Absolutely a good Kata, many thanks to the author
Julia translation Please review and approve
Thank you, for the Julia translation. Unfortunately, I have never used Julia before, so I am not sure how I could properly review your translation. Would someone proficient in Julia please review the translation and give me some feed-back, if they can't approve the translation themselves? Cheers!
Thanks
.
gosh, it's so hard.
is it mathematically possible?
or efficient iteration is the only way?
fffuuuu!@^%#@%#&@!
various attempt on JS keep swinging between 910k and 970k completion, on the last 1 million numbers.
it would be amazing to see others solution on JS after I complete this!
yes, I believe it is reasonalby hard :-) at least that was the intention.
algorithms that are linear in the input interval will certainly fail. But also logarithmic complexity algorithms might fail if they are not efficiently implemented.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
I doubt that there are still undiscovered mistakes in the test cases
the error messages means
conclusion: The test works as expected.
Unfortunately, I have no iea, what you wish to express. I you believe there is a mistake (which might very well be the case) try to make a proper argument and carefully describe, why you believe something is wrong. It is a huge pain to try to guess what some hastily typed comment might convey.
there is no matching edge case. Neither in the example test nor in the submission tests. Start and end don't show up for the fixed tests because you can see the values after successful submission, which is not the case for Random Tests, obviously.
i found an error in my code, sry & thx
p/s/ right line has been #ed out
It takes me 499ms on a test, but on attempt it fails due to time out. What could be wrong?
since I don't know your code I wouldn't be able to tell. The submission tests contain a large number of random tests. So if your code contains any inefficiency, it will certainly time out.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
well, if you can do it for 3 digits, you probably can do it for 1 digit. And then you are probably already very close to the solution. Good luck.
This comment has been hidden.
yes, this approach will certainly time-out. You will need something that is not linear in the difference between start and end.
Very cool kata. A performance
tag
should be added.It is not quite clear to me, what distinguishes the
optimization
and theperformance
tag. I have the impression that they are used rather interchangeablyAlready added by somebody.
I think I am having timeout error because of the huge numbers part, my code isnt long and I think it is efficient. It passes trhough all the other tests but when it gets to the last part I get the time error.
Im doing itt on JS btw
How is this an issue (= a bug in the kata)? Please read the documentation: https://docs.codewars.com/training/troubleshooting/
This is a hard kata.
This comment has been hidden.
My bad! Copy and paste error. Should be fixed now. Please check, if it works for you now.
It works, but I'm timing out now. I hope memoisation is not required for JS.
no, nothing fancy required. My solution is completed in 7870ms. But actually generating the random tests takes more time than running the solution. So it should not be too sensitive to minor optimizations in your code.
edit: I think I see the problem. A hint? Your solution takes 3069ms for the second set of random tests, mine takes 782ms.
I can't spot the difference.
This comment has been hidden.
approved!
Python
this should be fixed now. I put the reference functions into the
describe
block. Please re-check that the tests are now in the proper form.Looks good to me
thanks. Python is not my first language. So I am still learning... a lot.
Python should use
snake_case
instead ofcamelCase
for function names.fixed
CommonLisp: there should be no warnings when running tests:
All variables should be properly declared.
fixed.
This comment has been hidden.
Thanks! Maybe the number of random tests is too large? But on the other hand, it can be solved just with basic arithmetic operations.
I don't think it's too large. It's a performance kata afterall.