Skip to content

Instantly share code, notes, and snippets.

@TimCastelijns
Created December 14, 2015 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TimCastelijns/2496a51ff9f7dd04c6e5 to your computer and use it in GitHub Desktop.
Save TimCastelijns/2496a51ff9f7dd04c6e5 to your computer and use it in GitHub Desktop.
santa_x, santa_y = 0, 0
robot_x, robot_y = 0, 0
visited_santa = [(santa_x, santa_y)]
visited_robot = [(robot_x, robot_y)]
with open('day3.txt', 'r') as f:
s = f.readline()
santas_turn = True
for direction in s:
if santas_turn:
if direction == '>':
santa_x += 1
elif direction == '<':
santa_x -= 1
elif direction == '^':
santa_y += 1
elif direction == 'v':
santa_y -= 1
visited_santa.append((santa_x, santa_y))
else:
if direction == '>':
robot_x += 1
elif direction == '<':
robot_x -= 1
elif direction == '^':
robot_y += 1
elif direction == 'v':
robot_y -= 1
visited_robot.append((robot_x, robot_y))
santas_turn = not santas_turn
print len(set(visited_santa + visited_robot))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment