5 kyu
Palindrome integer composition
128 of 329KenKamau
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.
Haskell translation
Very interesting kata, well done.
This comment has been hidden.
python new test framework
lost time on a bug due to int overflow, replacement with long eliminated the bug
all tests Completed in 583ms
Wow this one took a long time to solve, I went through lots of iterations until it was optimised enough. Seemed harder than 5kyu to me. I really learned something about performance though! (Ruby)
Hi, my algorithm performs the 100M (one hundred million) Test in below 0.5 seconds. And yet I receive a 12 second timeout here at codewars.
Can anyone name me the solution count for 100M, just to be sure? I don't see how there can be that big difference in performance here and locally at mine.
Regards, Motl
As far as I see, there's ~100 tests with
n
going up to 10M. How long does your solution take for 100 different numbers?Hi, thanks for your reply. It seems, I'm walking on a tightrope here - sometimes I receive the timeout, sometimes not. Then, I'm somewhere about 11.5 seconds. :/ And: It passes for the small values, but I still seem to have a problem with big values. Here, my answers differ around "1" to "2". Since it's a little ... intransparent, I don't know where to edit.
Maybe your algorithm is not quite run efficiently with multiple large numbers. Think about it :D
I'm a step forward. All values are correct now, but ... my single number test takes around 0.13 seconds, so the 12s timeout is still a little hurdle.
(Is 0.13s for a single 10M test such a bad outcome, comparatively??)
This comment has been hidden.
There is no test for length of solution. So long solutions are ok.
expected:<...* 7^2 * 11 * 13 * 17[]> but was:<...* 7^2 * 11 * 13 * 17[ ] > So i delete the last symbol of result and get: expected:<2^[3 * 3 * 5]> but was:<2^[15 * 3^6 * 5^3 * 7^2 * 11 * 13 * 17]> What is wrong?
Tbh took me a while to pass in 12s :D
Hello,
How fast was your solution? Mine passes n = 10e7 in 1.394 seconds but it still times out during the random test.
[edit] for anyone wondering the threshold is to be able to return n=10e7 in approximately less than 1 second.
My code is too slow. How far off am I?
Passed: 82 Failed: 0 Exit Code: 1
Just passed the full suite test. 82 is fairly close, fyi.
All I can say for the next fighters: there is a solution with a performance 00.05 sec for 10M test. And this solution is amazing and simple. So don't give up as I did! )) but for now more then 50% from winners have 1dan or 1kyu and first time here I've found more then 5 solutions with cheater tricks )) you will see it later in solutions folder! )) This is very very funny!
I have been working on this kata 2 days. First algorithm I've made for 10 min and it goes through simple tests, but for big test (n=5 mln) I can't made it faster then 10 sec. I will improve it and I like this task, but I think this kata is harder then 5kyu. Also it would be good to accent in the task on test for really big sequences.
I've just found that the last test will take v=10E7...))) on 5 mln I had the best time 9 sec. I am in stuck! it's pretty upsetting me!
Just avoid list and repeated calc of the squares. Both is taking a lot of time. My results in sec:
n = 1.000: 0.0002543900000091 sec n = 10.000: 0.0019760499999847 sec n = 100.000: 0.0156731199999967 sec n = 1.000.000: 0.1389633400000093 sec n = 10.000.000: 1.4097446399999853 sec
Cool! I did calc for squares only one time. Where do you store the sequences? Tuples or sets or...? My time for 10M is 17 sec for now, but I did start from 25 sec ))) Your results is awesome!
I've changed things many times... use sets instead lists for speed, change all schemes! And all I can do is 15 seconds for n=10M! I am give up. And this is clearly not 5kyu! This is the first Kata that has ruined my mood. I've spent three days and it's all for nothing.
That is sad to hear, you are very close. But keep in mind that the kata is not about which numbers, just that a number is found.
Edit: nvm, be aware of duplicates
Clarification: legitimate sequences would be {1^2 + 2^2}, {1^2 + 2^2 + 3^2}, ..., {2^2}, {2^2 + 3^2}, {2^2 + 3^2 + 4^2}, ..., etc, right ?
If so, for n = 100 you get 5 and for n = 1000 you would get 16. Not sure if I have understood the explanation correctly. Any suggestions would be appreciated.
Please see description and example test cases.
for n = 100, there are only 3 numbers that meet the requirement. They are
5, 55, 77
.for n = 1000, there are only 11 numbers.
Thanks for the response.
The clarification is with the description. I wasn't sure if, for example, {2^2} is a valid sequence (sum of 1 elements). The min length of the sequence is not specified.
Either way, if min length of valid sequence is 2, then the test cases hold.
Cheers.
What's the largest value of n that can be tested in this kata? I passed all five tests in 1048ms (using python) but my code times out for the hidden tests. Any help would be appreciated!
10E7
Thanks!
Hey Could anyone tell me the numbers up to 200 that meet the requirements ... I'm just a bit lost.
5, 55, 77, 181,...
I would approach this by coming up with all possible numbers within the test range that are consecutive square sums. The first one would be
1^2 + 2^2
, then1^2 + 2^2 + 3^2
, and so on.Yeah thanks , I'm just a bit tired now .. will give it second chance tomorrow.
When testing large numbers, all my results have one extra palindrome. For example, when testing n= 1000000 is 60, n=5000000 is 78 and so on. I’ve checked each palindrome one by one and they all are correct. For example for n= 1000000 last one is 964469 (5662 + 5672 + 5682), for n=5000000 last one is 3187813 (12622, 1263**2). Is there an error in test results for large numbers?
Check your code. If you can pass the example tests, you should be able to pass the random tests. See B4B's messege below, admitting that this was a toughy for him and he's 1kyu. So please take your time.
Test results are correct - im guessing same number has been counted twice.
Did you ever come right with this? I have a similar issue in that I have more palindromes for very large numbers than are expected. I've checked, and don't see any duplicates
onlyonekenobie,
Hey first: nice name, haha. Second: I had this same error for a while, and figured out that a value was indeed duplicating. It must be that two sequences or something add up to this specific value or something, not entirely sure, but my fix was to check for duplicates, and just removed the duplicate then I had an accurate count.
Hopefully this helps!
Hi,
some suggestions:
(I had a hard time on this one... :/ )
Done!
Thanks for trying it out.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.