• Custom User Avatar

    Precomputations enabled by a small input domain are not cheats, they're optimisations.

    Newer JS versions have BigInt, which would allow for a larger input domain. That might actually solve this "problem". Scanning source code for patterns is a losing proposition.

  • Custom User Avatar

    Damn, I just wanted to post this after I completed the kata :D

  • Custom User Avatar

    verbatim what i wrote too! Party!

  • Custom User Avatar

    Just a small detail: \w refers to [a-zA-Z0-9_] (so it also contains the underscore and digits).

  • Custom User Avatar

    What? It's the most time efficient solution

  • Custom User Avatar

    The arity of the function does need to be taken into account. Since only functions which have already been declared may be called, the intepreter has all of the information it needs to make that call.

    As a more general example, take the following expression in Polish (prefix) notation:

    * + 1 2 2
    

    A prefix interpreter knows that + is a binary operator, so it takes the 1 2 as the arguments to +, then * takes the resulting 3 2, resulting in 6.

    Likewise, in your example the interpreter knows that echo is a unary function, so it takes only the first argument in the stack.

    Hope that helps. If there was any particular part of the description that led you to believe that arity wouldn't need to be taken into account, please let me know and I will try to clarify that section.

  • Custom User Avatar

    Thank you very much. You have helped me alot. Not only you have helped me to improve the kata description but I have also gotten a English class for free. Thanks again!

  • Custom User Avatar

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

  • Custom User Avatar

    Yes you're right: English is not my native tongue. I would be very grateful for your help. Thanks!

  • Custom User Avatar

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

  • Custom User Avatar

    no real reason. probably still mentally stuck in if/else syntax from other languages. if I were to write the solution again, I would likely use if