Ad
  • Default User Avatar

    Recurssion and iteration don't scale well. Factorial calculation with big numbers is a problem. The idea for this kata is to find a method that reduces the number of iterations/recursive calls to the minimum necessary to find a solution. You need a little bit of math before implementing a solution.

  • Default User Avatar

    There are other solutions without using a recursive implementation.

  • Default User Avatar

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

  • Default User Avatar

    Yes, I would like it if you do.

  • Default User Avatar

    I've updated the tests and added some comments here and there. Hope it helps.

    Please, let me know if you find anything else.

  • Default User Avatar

    This is actually the same as this:

    function tetrahedron(n) {
      n * (n + 1) * (3 * Math.ceil(n / 3) + (n - 1) % 3) / 6;
    }
    

    I should have seen this, and also that 3 * Math.ceil(n / 3) + (n - 1) % 3 is the same as n + 2

  • Default User Avatar

    I had replied before, but it looks like my reply was not posted.
    Anyway. Thanks for your comments. I have improved this kata a little bit. I now use 797651 in my tests.
    Let me know if you have any other improvement.

  • Default User Avatar

    About your first comment, you are right, but I can't figure out how to give a more helpful message without given away the answer expected in the tests (to prevent cheating). I've been thinking about showing the result of the user's calculation without showing the expected value. But I haven't checked the test suite, so I don't know how to do that (I don't know how to show anything other that a plain message). I'll have a look at it and try to improve it.
    On the other hand, maybe I could just give the right answer when a test fails, what do you think?

    About your second comment, I mean 'n > d'. The values will always be valid, so the user doesn't need to check anything and can focus on the math and the algorithm. If you have any suggestions about how to reword it I would appreciate it (English is not my first language).

    Ah, almost forgot, I have copied the answers to all the test from WolframAlpha and the "Correct solution" I posted passes the tests, so I'm inclined to think that there could be a problem with your solution. But, please, note that we are working with big numbers here, and although I've tried to make sure the tests don't exceed the limits maybe some browser versions behave differently. I'll try to check that.

    Let me see if I can improve it a little bit so it's easier to build a solution to the kata.

  • Default User Avatar

    What should I return when input is null or empty string?