aoc/2015/three/solution-2.py
2025-05-01 12:38:17 +03:00

33 lines
928 B
Python

with open("./input", "r") as f:
instructions = list(f.read())
cursor1 = [0,0]
cursor2 = [0,0]
houses = []
turn = 0
# turn 0 is santa, turn 1 is robosanta
for instruction in instructions:
if turn == 0:
if instruction == "^":
cursor1[0] += 1
if instruction == "v":
cursor1[0] -= 1
if instruction == ">":
cursor1[1] += 1
if instruction == "<":
cursor1[1] -= 1
houses.append(f"{cursor1[0]},{cursor1[1]};")
print("(*)" + str(cursor1))
turn = 1
else:
if instruction == "^":
cursor2[0] += 1
if instruction == "v":
cursor2[0] -= 1
if instruction == ">":
cursor2[1] += 1
if instruction == "<":
cursor2[1] -= 1
print("(-) " + str(cursor2))
houses.append(f"{cursor2[0]},{cursor2[1]};")
turn = 0
print(len(set(houses)))