46 lines
671 B
Python
46 lines
671 B
Python
# Fill Input
|
|
|
|
input = ""
|
|
|
|
try:
|
|
with open("03.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))
|