Add 1 -> 5

This commit is contained in:
PedroEdiaz
2025-10-29 17:19:47 -06:00
commit 62dade14e1
5 changed files with 139 additions and 0 deletions

44
2015/3.py Normal file
View File

@@ -0,0 +1,44 @@
#!/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))