2 kyu

Fastest Code : Equal to 24

531 of 962myjinxin2015
Description
Loading description...
Puzzles
Games
  • Please sign in or sign up to leave a comment.
  • Mafir Avatar

    Very nice kata! The task seemed innocuous at first, but it turned out to be quite a tough nut to crack. However, with persistence and the right idea, I managed to solve it after all. Thanks for this experience. I learned a lot!

  • churchkhelass Avatar

    больше чем 220 я не успеваю за 12 секунд либо я реально не могу быстрее сделать либо сервакам урезали мощность

  • Yushi.py Avatar

    I pressed "attempt" 30 times :)

  • TheChildOfProphecy Avatar

    This comment has been hidden.

  • nleea Avatar

    Traceback (most recent call last): File "/workspace/default/tests.py", line 83, in A,B,C,D = filter(lambda x: len(x), re.split("[^\d.]+", useran)) ^^^^^^^ ValueError: not enough values to unpack (expected 4, got 1)

  • Obaskly Avatar

    Execution Timed Out (12000 ms) :/

  • izferriss Avatar

    fair warning, I am brute forcing with 10000+ lines... receiving the following after passing basic tests:

    TypeError: s.match is not a function at isValidR at /home/codewarrior/index.js:10920:16 at /home/codewarrior/index.js:10942:5 at Object.handleError

    /runner/frameworks/javascript/cw-2.js:237 throw ex; ^

    TypeError: s.match is not a function at isValidR (/home/codewarrior/index.js:10935:8) at /home/codewarrior/index.js:10920:16 at /home/codewarrior/index.js:10942:5 at Object.handleError (/runner/frameworks/javascript/cw-2.js:233:11) at Object. (/home/codewarrior/index.js:3:6) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) at Module.require (module.js:596:17) at require (internal/module.js:11:18) at [eval]:1:1 at ContextifyScript.Script.runInThisContext (vm.js:50:33) at Object.runInThisContext (vm.js:139:38) at Object. ([eval]-wrapper:6:22)

  • jjpxiii Avatar

    This kata was great ! Would you happen to know some other cool katas with performance constraints ?

  • Yinsky Avatar

    this is really intresting. if you have complete the primer question. you can try to decrease your complexity, it will get pass the test.

    the primer question code may only pass half of test cases.

  • lopared Avatar

    Test case is incorrect.

    Python test case failed. Test for: a=30,b=40,c=9,d=4  Example solution: "It's not possible!" 
    
    '(9*(4-(40/30)))' should equal "It's not possible!"
    

    This is a mistake since 9*(4-(40/30)) is indeed 24.

  • Jari Jarvis Avatar

    Is there a chance that the author can remove the print statements?

  • x_elf Avatar

    I see some posted (python) solutions that only passed because they hit attempt a few times in a row until they got a set that didn't have the test case they missed.

    Suggest you add these test cases:

    Test.describe("x_elf Tests")
    print("this one can return ((87*20)-84)/69, your answer is:",equal_to_24(87,20,84,69))
    Test.assert_equals(eval(equal_to_24(87,20,84,69)) , 24)
    print("this one can return 72/((6*16)-93), your answer is:",equal_to_24(72,6,16,93))
    Test.assert_equals(eval(equal_to_24(72,6,16,93)) , 24)
    print("this one can return (98/(76-74))-25, your answer is:",equal_to_24(98,76,74,25))
    Test.assert_equals(eval(equal_to_24(98,76,74,25)) , 24)
    
  • brendanvos Avatar

    Log prints "--------20 Random Test--------" when it's actually performing 500. Correcting this would help users know how far off the mark they are.

  • brendanvos Avatar

    If you meet the time limit but fail a test you get the "Congratulations, You pass the test!" message

  • seanac Avatar

    I got the error message "'80/((76/3)-22)' should equal "It's not possible!"" but 80/((76/3)-22) is in fact equal to 24.

  • olizh Avatar

    This comment has been hidden.

  • FArekkusu Avatar

    The description is badly formatted.

  • muralikboddu Avatar

    Can you fix this issue. All cases are passed but i see this STDERR while running random test cases.

    Traceback (most recent call last): File "main.py", line 83, in A,B,C,D = filter(lambda x: len(x), re.split("[^\d.]+", useran)) ValueError: not enough values to unpack (expected 4, got 1)

  • muralikboddu Avatar

    to the author. can i get some help. i am getting issue with running random test case. all cases are fine but i see this error.

    Traceback (most recent call last): File "main.py", line 83, in A,B,C,D = filter(lambda x: len(x), re.split("[^\d.]+", useran)) ValueError: not enough values to unpack (expected 4, got 1)

  • muralikboddu Avatar

    i am getting issue with running random test case. all cases are fine but i see this error

    Traceback (most recent call last): File "main.py", line 83, in A,B,C,D = filter(lambda x: len(x), re.split("[^\d.]+", useran)) ValueError: not enough values to unpack (expected 4, got 1)

  • szabope Avatar

    Hi,

    What I got: Test for: a=28,b=32,c=3,d=88 Example solution: "It's not possible!" '32/((88/3)-28)' should equal "It's not possible!"

    However 32/((88/3)-28) == 32/((88/3)-(84/3)) == 32/(4/3) == 8 * 3 == 24 ... well, according to math

  • Hana1989 Avatar

    Hi, Python test cases doesn't work without "import math". It should be fixed.

  • anter69 Avatar

    Python:

    • number range is 1-13, not 1-100 as stated in the description;
    • eval is not protected (can be redefined);
    • reference solution could/should be faster;
    • expected and actual values are swapped in the random tests;
    • returning the wrong result breaks the test suite:
     STDERR
    Traceback (most recent call last):
      File "main.py", line 79, in <module>
        if abs(eval(useran)-24)<0.00000000001:
      File "<string>", line 1
        It's not possible!
                         ^
    SyntaxError: EOL while scanning string literal
    
  • Jo Kim  Avatar

    I get always SyntraxError EOL and it points to end of return "It's not possible!". But I couldn't get what is wrong. I checked everything. It seems to be an error of your test script. It seems because "It's not possible!" is not evaluable ...

  • Glyxerine Avatar

    Ruby translation

    Please check and approve if possible :)

  • olizh Avatar

    This is hard and fun! The test is also very useful. Thanks a lot!

  • Folgiro Avatar

    This comment has been hidden.

  • Jomopipi Avatar
  • C-V Avatar

    C++ translation published :)

    (It provides a Math::eval function (since C++ doesn't have eval()), which only works with mathematical expressions, and should be fast enough. I hope you don't mind ?)

  • 讨厌走开啦 Avatar

    random test give 8/(1-(48/72)), so try

    Test.assertSimilar(eval("8/(1-(48/72))") , 24);

    but i got

    Expected: '24', instead got: '23.999999999999996'

  • kontic Avatar

    This comment has been hidden.

  • metalim Avatar
  • metalim Avatar

    This comment has been hidden.

  • dayfine Avatar

    This comment has been hidden.

  • docgunthrop Avatar

    This comment has been hidden.

  • chinesedfan Avatar

    This comment has been hidden.

  • stackcats Avatar

    this one can return 2*(13-(7/7)), your answer is: 2*(13-7/7) what's difference between 2*(13-(7/7)) and 2*(13-7/7)?

  • hufftheweevil Avatar

    Because of the way the test suite is setup, if your function returns "It's not possible!" but the test is expecting an expression that it can eval, then CW throws an syntax error. At first glance, it doesn't really make any sense, and I wonder if it could confuse other people as well. I would suggest adjusting the tests to catch this error and return a more approriate error to the user.

  • Voile Avatar

    Approved

  • K01egA Avatar

    I think you should mention that result could be not strictly equal to 24, e.g. here 36*(1-8/24)

    Thank you for the nice kata. It would be nice to have version of this kata not limited by 4 arguments and 24.

  • NikosAthens Avatar

    Is there a Python solution? How can I code it in Python?

  • gabbek Avatar

    Holy crap this was hard. I'll share my solution tomorrow :) thank you so much! No idea how you come up with all those clever solutions... took me a while to get it working ;) Rated as 2kyu, will think of rank a bit more after there'll be some more solutions.