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 had the same error. They should have specified that the condition is can he live until the beginning of year N, and not the end, therefore you only calculate n-1 times
There is a better solution. My machine computes the answer for n=100 in less than 4 seconds. If you want to test it the answer is
"Range: 7412080755407363 Average: 4323892498073.29 Median: 1859362246.00"
This comment is hidden because it contains spoiler information about the solution
You lose precision because of
double
's involved. A workaround for anO(1)
solution would be not to dopow(n, 4)
, but find another approach, so you don't end up with very big floats. Otherwise rewrite your solution in language with arbitrary integer size.I'm not sure it's an integer overflow, sometimes it calculates slightly over or under. Changed the calculation to use
In this specific order: sum=n*(n+1)/2n(n+1)/2
Somehow it has to be like this or it wont calculate properly.
You're probably having an integer overflow.
This comment is hidden because it contains spoiler information about the solution
I used C++, my code passes the actual tests just fine though.
I made a similar algorithm to yours and got the same error. The problem was that when I modulo 101^exp, I got the result of 1, which was used as the exponent for the next number.
This problem happens whenever base^exp ends with .....0x. So modulo cuts the number to the ending digit x, which makes the next steps for that case into 2^(2^1)=2^2-1. Whereas 2^(2^101)=2^(long number which ends with....52) = long number which ends with 6.
Try changing the algorithm to do something slightly different for these cases.
Given the only language he trained is C++ I guess that's the language.
Looks like expected and actual results are swapped in error message. Which language are you using?
There seem to be a sample test which I'm consistently failing.
Case 1: 83 6 2 ---> Expected: 9 Actual: 1
83^(6^2) = 83^36
I used a calculator 3^36 = 150094635296999121
I've already passed the Kata
Hello, I tested my code for n=50 on codewars and on my machine. Codewars got the answer in 2203 ms and my machine 291 s. It kind of brute forces its way through partition generation, so I expected it to take a while. It's good news that it didn't time out, but does that make my computer a potato?
For confirmation, both codewars and my machine returned range=86093441 when n=50. Spent some good hours on this and had a great time.
It's just how the tests are written. It certainly could have been written to accept another type of data format. I thought it was sort of an odd choice myself.
Wow that was very hard. Is it possible for an int or vector return value to be accepted? Can someone explain why it needs to be string?
Loading more items...