Created
December 14, 2015 11:22
-
-
Save TimCastelijns/2496a51ff9f7dd04c6e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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