diff --git a/buggy.py b/buggy.py
--- a/buggy.py
+++ b/buggy.py
@@ -33,7 +33,7 @@
 for i in range(1, H + 1):
     for j in range(4):
         for k in range(4):
-            if (k & 1) ^ (j & 2) == 1:
+            if (k & 1) ^ (j >> 1 & 1) == 1:
                 continue
             if maze[i - 1][j ^ k]:
                 if i == H:
