Ad
  • Custom User Avatar

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

  • Custom User Avatar
  • Custom User Avatar

    I used very similar reasoning on both methods in my solution, but I tried to go for a readable code ando also followed PEP8, resulting in 38 lines against 9.

    This solution uses some very cool tricks though, some of which I can surelly use to improve mine.

    Congrats on the most succinct solution!

  • Custom User Avatar

    thanks a lot

  • Custom User Avatar

    For working with an outside IDE, can I run the sample tests of a kata without having to change their pattern? For example, I'd like to have access to Test.describe, test.assert_equals and whatever else I may find in sample tests. Do those come from any particular public package or are they exclusive to Codewars?

  • Custom User Avatar

    I have a question not entirelly related to this kata, but I couldn't find another place to post it.

    It was recommended to me previously to use an outside IDE for coding for longer katas, and I decided to try that. That said, is there a way for me to run the sample tests without changing them or their pattern? Is there a package I can import that gives me access to Test.describe, test.assert_equals and whatever else I may find in sample tests?

  • Custom User Avatar

    Well, I in fact had not run the code yet as I knew it wasn't ready, and I suppose I'm not the only one who does so when solving complex problems. That said, the knowledge that the code is only saved upon testing/attempting can not be expected from an user. Thus, I suggest a periodical, more reliable saving mechanism.

    Furthermore, I'll be more carefull from now on and hit Test prematurelly just for the purpose of saving my code. Thank you for the instructions.

  • Custom User Avatar

    Shouldn't the code I'm writing for a kata be saved, at least, periodically?

    I was solving a problem using the website's IDE and decided to exchange a function name for a more meaningfull one. Since it was already being called multiple times throughout the code, I decided to try and automatically replace it. By pressing CTRL+F, I was shown an in-built "Find" tool, with no replacing option though. Then, as a fool, I pressed CTRL+R in hope that a similar tool for Replacing would show. Instead, my browser refreshed and I lost about an hours work... Since the UI has no apparent "Save" button, I expected my code to be persistent to at least some degree.

  • Custom User Avatar

    Btw, I didn't mean to be arrogant. I'm new to this website and might be wrong. Still, in my point of view, this is a way of cheating, and I provided 3 arguments as to why I think so. I would appreciate it if you could present any counter arguments.

  • Custom User Avatar

    But the problem definition does not specify an upper bound for the values of m and n. The only way to ensure that the hardcoded values are broad enough is through trial and error, what thus only garantee that the program is correct for the presently given tests, which do not represent the whole of the problem (as of the description). If tests with higher numbers were added, for example, it would break.

    That said, even if the warrior had to write the actual code to find the numbers, as you mentioned, that code is not included here, and thus it's bypassing the execution time constraint. As for your precalculation argument, I imagine one can still run a precalculation routine here, only once, by using memorization, unless the variables are reset and the code is reinterpreted between each test, which I find unlikelly.

    Think of it like this: If I were to print out all the tests of a problem, write a program which can solve it elsewere, compute all the awnsers and present here anther program which simply access a hardcoded mapping of question->awnser, I would be cheating, right? Would work though, and fast. This is, partially, in my opinion, what this solution does.

  • Custom User Avatar

    this is not clever, this is a cheat

  • Custom User Avatar

    There is a Python test case containing "(2", with no space in between the operator and the number, as described in the problem definition.

  • Custom User Avatar

    Has this kata changed at some point? I'm confused, the top voted Python solutions seem not to deal with parentheses at all...

  • Custom User Avatar

    I'm sorry, but this is awfull in terms of both time and space complexity

  • Custom User Avatar

    poor readability.

    I solved this kata essencially the same way, but tried using some indentation to make it more understandable