Ad
  • Default User Avatar

    Well, first of all its good that you are not taking my words offensively. :)
    "In English and programming, groups can be made using symbols such as "()" and "{}" that change meaning." - when I read this it implies that there is some meaning in English and/or programming context. Brackets have no meaning on its own, so this tells me that tests just not complete. Anyway this is just me.

  • Custom User Avatar

    What I'm reading in the description is the input string can only contain braces of three sorts, and nothing else.

    The kata tests support this understanding.

    So I'd say you're trying to see this kata as something more than it actually is. :)

  • Default User Avatar

    While this code works for checking strings with only brackets, it fails if you call like so group_check("(something)"). Which in my understanding is a must.(read description).
    I'm commenting here not to show that I'm better programmer. Quite opposite, I'm trying to learn programming that why I study the best solutions.

  • Custom User Avatar

    Thank you for explaining, jolaf, I think the stack concept is going to come in handy when keeping track of things that can be thought of as pairs. The dictionary pairings was a 'key' insight as well. I'm thinking this might work for higher order tuples as well. Its like counting sets, where once you have a complete set, you throw(pop) them away. Could perhaps do a left-append and left-pop as well when there are 4 of a kind. Though it probably is better to switch to an table or something like that for more complex accounting.

  • Custom User Avatar

    not stack returns True if stack is empty.

    That should be the case at the end of the function if braces are set correctly.

    In general, it works like this:

    • Iterate over character in the string.
    • If we encounter an opening brace, put the respective closing brace to the top of the stack.
    • If we encounter the closing brace, make sure it's equal to the one at the top of the stack.
    • If that not the case, it means the braces order is incorrect and we should return False.
    • At the end, the stack should be empty (otherwise it means some open brace was not properly closed).
  • Custom User Avatar

    Anyone want to explain how this is working? I get lost at "elif not stack or stack.pop() != b:" and I don't get how "not stack" returns True

  • Custom User Avatar

    I really like this solution. Probably because I tried a similar logic, but this code is SO much cleaner and shorter than mine. Teaches me a lot to wade through it.