Ad
  • Default User Avatar

    The description states, "Your function will take an input string that may contain any of the symbols "()" "{}" or "[]" to create groups."

    In other words, the string will only contain those characters. It's trivial to make a single passthrough to remove any other characters, so I didn't think that it added anything to the problem to include them.

  • Default User Avatar

    This challenge definitively requires more than basic regex (traditional regex is essentially a finite state machine, which has no 'memory', so couldn't record past braces). While it can be done with more advanced regex, that's much slower and other solutions are far more elegant.

  • Default User Avatar

    Wow, it's been a while, I'd forgotten about this site for a bit! I approved your translation an the Haskell translation, thanks for making it!

  • Default User Avatar

    You didn't pass all the tests, sorry! You're missing an edge case, the empty string. It specifies in the problem description that the empty string should be counted as a proper group, and thus return true. I can't see your code, but I'm guessing that it assumes at some point that the string is non-empty, and grabs the first element, which of course doesn't exist if the string is empty.

  • Default User Avatar

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

  • Default User Avatar

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

  • Default User Avatar

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

  • Default User Avatar

    True. The difference in most cases would be negligible, but if this was to be repeated or performed on large strings, your O(n) method would be better (thought it does add some space complexity).

    I mostly use python for quick, dirty scripts like this one anyway. I don't know why people are upvoting this one as best practice - it just looks nice, it's not really best practice.

  • Default User Avatar

    Well, it says in the problem description that the test strings will only contain those symbols. Actually, when I first started writing this, I considered that, but I thought it would just be a needless addition that distracts from the actual problem - a quick two line for loop or one line regex removes that element altogether, so I thought it didn't really add anything to the problem.

  • Default User Avatar

    May I see your code? I can't see it on my end. Sorry about the float thing. I always forget to type cast when I'm working with Python.

    I'm not sure what could be wrong with the testing code. This is the line that actually does the test:

    test.assert_equals(f(n, m), solution(n, m))

    Which is fairly standard, to my knowledge.

  • Default User Avatar

    My code has been timing out for no reason lately - at first I thought it was the code itself, but it worked in my local environment, and then my suspicions were confirmed why I simply typed "return 0" and that also timed out. What's going on?

  • Default User Avatar

    Nice little math problem. Python translation kumited

  • Default User Avatar

    Best practice would be to just write

    return sorted(map(str, str(x)) + map(str, str(y))) == sorted(map(str, str(x * y)))

    There's little need for a ternary operator in this situation.

  • Default User Avatar

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

  • Default User Avatar

    It's been a while with no response, so I'm going to mark this as resolved - I don't think it's an issue with the kata. Feel free to come back anytime and I'll be happy to help work out the issue.

  • Loading more items...