Files
aoc/2015/3.py
PedroEdiaz 62dade14e1 Add 1 -> 5
2025-10-29 17:19:47 -06:00

45 lines
691 B
Python

#!/usr/bin/env python3
# Fill Input
input = ""
try:
with open("3.txt", 'r', encoding='utf-8') as file:
input += file.read()
except Exception as e:
print(f"An error occurred: {e}")
# Convert Corrdenate to string
def key_coord(coord):
return f"{coord[0]},{coord[1]}"
# Result
santas = 1 # or 2
i=0
coords = [[0,0],[0,0]]
houses = {key_coord([0,0]): santas}
for c in input:
match c:
case '>':
coords[i][0]+=1
case '<':
coords[i][0]-=1
case '^':
coords[i][1]+=1
case 'v':
coords[i][1]-=1
# A Dictonary for all the visisted houses
key=key_coord(coords[i])
if key in houses:
houses[key]+=1;
else:
houses[key]=1;
if santas > 1:
i^=1
print(len(houses))