The Labyrinth input() bug

Hi there,

I’ve been trying to complete the Labyrinth puzzle, but once the character arrives to the control room the input() function on the last row doesn’t respond causing my code to fail (actually, it works in the first test case but only there)

This is my input() handling code:

while True:
    kr, kc = [int(i) for i in input().split()]
    print(str(kr) + ", " + str(kc), file=sys.stderr)
    pos = Vector(kc, kr)
    maze = []

    for i in range(r):
        row = input()
        print(row, file=sys.stderr)
        maze.append(row)

and here is the normal input:
5, 14
???####…##??
???.##########??
???.#…T##??
???..#…#.#######.??
???#######…#####.??
???#C…#####.##???
???###…##???
???#.########…???
???.##…####???
???
???
???
???
???
???

(15 lines)

and here is the input wen entering the control room:
5, 13
???####…##??
???.##########??
???.#…T##??
???#…#…#.#######.??
???.#######…#####.??
???.#C…#####.##???
???.###…##???
???.#.########…???
???.##…####???
???
???
???
???
???

(14 lines)

I have the same problem.

The problem lies in the sys.stderr buffer. If the code section that follows a write operation into sys.stderr, this buffer will not be flushed, and its content will not be printed.

To force printing, you need to manually flush the buffer associated with sys.stderr. You can do this by simply calling sys.stderr.flush().

I suggest that you use the following simple debug function instead of printing to sys.stderr:

def debug(*args, **kwargs):
    print(*args, **kwargs, file=sys.stderr)
    sys.stderr.flush()