Ad
  • Custom User Avatar

    Sorry for accusing you of that. :P Problem may have been that the reference solution was modifying its input.

  • Custom User Avatar
  • Custom User Avatar

    Is this issue resolved now that JohanWiltink has updated the javascript translation?

  • Custom User Avatar

    You were modifying the input, weren't you? :]

  • Custom User Avatar

    There was a little problem with my code which made it super slow. Now only O(n) solutions should pass.

  • Custom User Avatar

    Glad you liked it :)

    Hmm. I wrote the Python and Ruby translations but not the JavaScript because I was unfamiliar with the bigInt library. Thanks for letting me know, I'll have to see about trying to make it so true n^2 solutions (and your second solution does appear to be one) fail. That's certainly the shortest solution I've seen yet :)

  • Custom User Avatar

    If you were mutating the array, then the tests were generated improperly, Now the tests are corrected to be generated correctly

  • Custom User Avatar

    sorry, the reference solution still returns false on that test case.

  • Custom User Avatar

    Details in performance tests:

    100 Random Tests --- Testing for code performance
     Your code should run as fast as a rocket ;-)
     Log
    Testing for:
    arr = [...1000001 elements] 
    Test Passed: Value == '12ms'
    Test Passed: Value == 557872
     Log
    Testing for:
    arr = [...1000001 elements] 
    Test Passed: Value == '6ms'
    Test Passed: Value == 596695
     Log
    Testing for:
    arr = [...1000001 elements] 
    Test Passed: Value == '5ms'
    Test Passed: Value == 594965
     Log
    Testing for:
    arr = [...1000001 elements] 
    Test Passed: Value == '7ms'
    Test Passed: Value == 549057
    

    So, it seems no problem ;-)

  • Custom User Avatar

    My solution's results:

    Test Results:
     Basic Tests
     It should works for basic tests (5 of 5 Assertions)
    Completed in 7ms
     100 Random Tests --- Testing for correctness of solution
     It should works for random tests too. (100 of 100 Assertions)
    Completed in 33ms
     100 Random Tests --- Testing for code performance
     Your code should run as fast as a rocket ;-) (200 of 200 Assertions)
    Completed in 5700ms
     Log
    Your code running in range 5ms - 12ms
    
  • Custom User Avatar

    Random test is reusing the same array object to perform its own computation to check if your solution is valid, so you shouldn't mutate the original array.

  • Custom User Avatar

    Thanks, glad you liked it!

  • Custom User Avatar
  • Custom User Avatar

    @Grae-Drake, the example is correct.

    The idea is:

    numbers: [a, b, c, d], rules: [f, g]
    [f(a, b), c, d]
    [g(f(a, b), c), d]
    f(g(f(a, b), c), d)
    

    Applied to numbers [2.0, 2.0, 3.0, 4.0] and rules [(a,b) => a + b, (a,b) => a - b]

    [(2.0 + 2.0), 3.0, 4.0]
    [((2.0 + 2.0) - 3.0), 4.0]
    (((2.0 + 2.0) - 3.0) + 4.0)
    
    (steps from the description)
    1. Rule 1: First number + second number -> 2.0 + 2.0 = 4.0
               2.0 + 2.0
    2. Rule 2: result from step before - third number -> 4.0 - 3.0 = 1.0
               (2.0 + 2.0) - 3.0
    3. Rule 1: result from step before + forth number -> 1.0 + 4.0 = 5.0
               ((2.0 + 2.0) - 3.0) + 4.0
    
  • Custom User Avatar

    CodeWars seems to have made some changes. I revised the kata and it should work for you now.