Walking in Circles

Python for AIHard+10 XP+10

Walking in Circles

A walker starts on square (0, 0) of a grid that goes on forever. moves is a list of one-letter steps:

stepchange to (x, y)
"N"y goes up by 1
"S"y goes down by 1
"E"x goes up by 1
"W"x goes down by 1

Task: write first_revisit(moves). Return the first square, as a tuple (x, y), that the walker stands on for the second time.

  • The start square counts as visited before the first step.
  • If the walker never returns to a square, return None.

Examples

moves = ["N", "E", "S", "W", "N"]
returns [0, 0]
moves = ["E", "E", "N"]
returns None

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run