Ad
  • Custom User Avatar

    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

  • Custom User Avatar

    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"

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    You lose precision because of double's involved. A workaround for an O(1) solution would be not to do pow(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.

  • Custom User Avatar

    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.

  • Custom User Avatar

    You're probably having an integer overflow.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    I used C++, my code passes the actual tests just fine though.

  • Custom User Avatar

    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.

  • Custom User Avatar

    Given the only language he trained is C++ I guess that's the language.

  • Custom User Avatar

    Looks like expected and actual results are swapped in error message. Which language are you using?

  • Custom User Avatar

    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

  • Custom User Avatar

    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.

  • Custom User Avatar

    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.

  • Custom User Avatar

    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...