Ad
  • Custom User Avatar

    Those strings methods are indeed more clever than I thought, which was "it won't replace/match a pair if in between are other brackets". Well, it turned out that it still works and for me this solution is the most clean one. I wonder how performant is it and why you use +2 in the loop? I have tried to loop over len(str) and it works as well.

  • Custom User Avatar

    I haven't seen yet such usage of an . in an import statement. It this rather simple example it makes things much more readable.

  • Custom User Avatar

    I'm not so far and right now I'm struggling a bit with the solution for the Reduce Directions kata.

  • Custom User Avatar

    Hi, Thanks for the comment. Yes, the named return value here is just for reducing the number of lines, and make the code enjoyable, since it s just 9 lines of code. I did enjoy writing it. Right now I am thinking about n-queens on 1000x1000 chess board to solve it under 10 seconds. let me know if you have a 10-second solution :)

  • Custom User Avatar

    Yeah, as I recall that scenario threw me at first too. In my first attempt I wasn't doing the b < 0 check inside the loop, only ckecking for b == 0 at the end.

  • Custom User Avatar

    Why does it work?

  • Custom User Avatar

    I came up with the same concept but I cannot handle a case with unmatched parenthesis like ())(. It turned out that it's much easier than I thought.

  • Custom User Avatar

    Yeah, me too. It can be sometimes really so simple.

  • Custom User Avatar

    That's a pretty neat solution. I wanted something similar but I couldn't think of a good solution to retrieve a searched value of ok. The usage of named return I find also quite clever but at the same time it's not very obvious (I didn't know that a variable inside the loop can be named the same as the returned varsiable).