Ad
  • Default User Avatar

    Thanks @geoffp - after attempting to read and reread this kata and going slightly mad thinking I couldn't understand it, you've explained it in such a nicer way.

  • Default User Avatar
  • Default User Avatar

    My python code is passing all tests, but times out in the performance section after about 190 tests. I have tried different approaches and on my laptop the code executes in less than 0.1 seconds for arrays as large as 50000 and numbers in the array as large as 1000000. I am struggling to find a more efficient solution. Any one can give me a pointer? Thanks.

  • Default User Avatar

    Most fun kata I've seen so far but the description really needs to be improved.

  • Default User Avatar

    Someone should rewrite the description of this kata. I see many complaints below pointing out that the algorithm is incompletely specified.

    This is what the description should have said:

    Choose any two array elements X[i] and X[j] with X[i] > X[j]. Set X[i] = X[i] - X[j].

    Repeat until no more subtractions are possible (because all array elements are equal).

    It can be shown that whenever there is more than one possible choice of the pair i,j, it doesn't matter which pair you choose: the answer will be the same in the end.

  • Custom User Avatar
  • Custom User Avatar

    In the example the two highest elements are selected each time, likely because it meant the author had to write less lines. You can select any two non-equal elements at random and reach the same answer.

  • Custom User Avatar
  • Custom User Avatar

    Your code's time complexity is exceesibly high and a more optimized solution can be deduced

  • Default User Avatar

    Before to even be a programming challenge, this kata is a total riddle as for directives.
    Reading if X[i] > X[j] then X[i] = X[i] - X[j], one expects a left to right parsing, and only for immediate neighbour. But then one has to decrypt the example. Let's try with arrow in other direction:

    X = [6, 9, 21]
    X_1 = [6, 9, 12] # <- X_1[2] = X[2] - X[1] = 21 - 9
    X_2 = [6, 9, 6]  # <- X_2[2] = X_1[2] - X_1[0] = 12 - 6
    X_3 = [6, 3, 6]  # <- X_3[1] = X_2[1] - X_2[0] = 9 - 6
    X_4 = [6, 3, 3]  # <- X_4[2] = X_3[2] - X_3[1] = 6 - 3
    X_5 = [3, 3, 3]  # <- X_5[1] = X_4[0] - X_4[1] = 6 - 3
    

    It seems we first substract 2 from 3, then 1 from 3, then 1 from 2, then 2 from 3, but lastly we substract 2 from 1. Not left to right, not immediate neighbours, so what? Deep right to left parsing? Greater from next greater? Greater from lower? Strictly none of those. Let's assume it's a deep right to left as far as possible then ending as possible. But what if [21, 9, 6]? Plus three poor test cases, can't help a lot.

    I really like puzzles, and this one could be great as a puzzle if it was clearly stated. If it's not a puzzle, then some things should be clarified, as a lot of people already noticed in discussion. Personnaly, I feel that tagging it as puzzle and replacing misleading instructions with some more examples/tests, would been more interesting… Then one can try it only when in "puzzle solving" state of mind.

  • Custom User Avatar

    Approved

  • Custom User Avatar

    Approved by someone

  • Default User Avatar

    "you would then check starting from the right again" this does not fit an example.

    X_1 = [6, 9, 12] # -> X_1[2] = X[2] - X[1] = 21 - 9
    X_2 = [6, 9, 6]  # -> X_2[2] = X_1[2] - X_1[0] = 12 - 6
    X_3 = [6, 3, 6]  # -> X_3[1] = X_2[1] - X_2[0] = 9 - 6
    X_4 = [6, 3, 3]  # -> X_4[2] = X_3[2] - X_3[1] = 6 - 3
    X_5 = [3, 3, 3]  # -> X_5[1] = X_4[0] - X_4[1] = 6 - 3
    

    Then you check an element even if its fit x[i] > x[j], you keep going witout reseting the line, so after make(x[2]) = 3(x[2]) - 2(x[1]) , you next step is check if 1(x[2]) > 1(x[0]).
    Am i wrong?

  • Custom User Avatar

    The most difficult parts of such katas is to determine what the blood it`s about.
    A did not get it (((

  • Custom User Avatar

    TypeScript translation based on existing JavaScript translation.

  • Loading more items...