1
0
Fork 0
advent-of-code/2015/aoc_d3p2.py

39 lines
1.3 KiB
Python
Raw Permalink Normal View History

2024-02-08 09:55:40 +01:00
#!/usr/bin/env python
visited_houses_human = []
current_house_human = (0, 0)
visited_houses_robot = []
current_house_robot = (0, 0)
count = 0
with open("inputd3.txt", "r") as f:
for input in f:
for x in input:
if x == "^" and count % 2 == 0:
current_house_human = (current_house_human[0] - 1, current_house_human[1])
elif x == "^" and count % 2 == 1:
current_house_robot = (current_house_robot[0] - 1, current_house_robot[1])
elif x == "v" and count % 2 == 0:
current_house_human = (current_house_human[0] + 1, current_house_human[1])
elif x == "v" and count % 2 == 1:
current_house_robot = (current_house_robot[0] + 1, current_house_robot[1])
elif x == ">" and count % 2 == 0:
current_house_human = (current_house_human[0], current_house_human[1] + 1)
elif x == ">" and count % 2 == 1:
current_house_robot = (current_house_robot[0], current_house_robot[1] + 1)
elif x == "<" and count % 2 == 0:
current_house_human = (current_house_human[0], current_house_human[1] - 1)
else:
current_house_robot = (current_house_robot[0], current_house_robot[1] - 1)
if count % 2 == 0:
visited_houses_human.append(current_house_human)
else:
visited_houses_robot.append(current_house_robot)
count += 1
print(len(set(visited_houses_human + visited_houses_robot)))