Ad
  • Custom User Avatar

    That makes a lot of sense. Thank you so much!

  • Custom User Avatar

    Check out the Python docs, especially the "Important warning!"

  • Custom User Avatar

    The prev = [(0,0)] part in your function introduces a subtle bug which does not manifest in other environments because your tests are incomplete.

    Thank you so much. Could you explain more as to why the prev = [(0,0)] part intrudces a subtle bug? Does it have something to do with how it is stored in global environment as opposed to local one within each iteration of recursion? And why don't I see the same problem with other parameters: i.e., x=0, y=0?

  • Custom User Avatar

    Change the last lines of your code to this:

    # ...
    # Check if new coordinates are out of bound
    def out_of_bound(x, y, size):
        return x < 0 or y < 0 or x >= size or y >= size
    
    maze = "\n".join([
            "...",
            "WWW",
            "W.." 
        ])
    print(path_finder(maze))
    
    # This test case gives different answers for me. Should return True, but it returns False in Codewars
    maze = "\n".join([
            "...",
            "W.W",
            "W.." 
        ])
    print(path_finder(maze))
    

    You can run it in https://programiz.pro/ide/python and you will see how your function returns False twice, while the second input should result in True.

  • Custom User Avatar

    It's just frustrating that Codewars seems to behave differently from other iterpreters.

    It really does not. It's problem with the tests you do in other interpreters. Your tests are incomplete.

    Codewars uses exactly the same Python as other places, you just perform your tests incorrectly. The prev = [(0,0)] part in your function introduces a subtle bug which does not manifest in other environments because your tests are incomplete. Try running your solution twice in any other place and you will notice the same problem.

    Your solution has a bug, it's not a problem with Codewars' Python.

  • Custom User Avatar

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