Files
aoc_2024/day8.py
Marguerite Miallier 3fdb680747 jour 7 qui marche pas
2024-12-08 22:00:55 +01:00

74 lines
2.2 KiB
Python

import numpy as np
from collections import Counter
l = ["............",
"........0...",
".....0......",
".......0....",
"....0.......",
"......A.....",
"............",
"............",
"........A...",
".........A..",
"............",
"............"]
with open('aoc_2024/day8.txt') as f:
l = f.read().splitlines()
freqs = {}
positions = []
nodes = []
def check_in_map(coords,l):
if coords[0] >= 0 and coords[0] <= len(l) - 1:
if coords[1] >= 0 and coords[1] <= len(l[0]) - 1:
return True
return False
for i in range(len(l)):
for j in range(len(l[i])):
if l[i][j] != '.':
freq = l[i][j]
if freq not in freqs.keys():
freqs[freq] = [[i,j]]
else :
freqs[freq].append([i,j])
positions.append([i,j])
print(freqs)
for freq in freqs.keys():
for index,coords in enumerate(freqs[freq]):
for index2,coords2 in enumerate(freqs[freq]):
if index!=index2:
diff = np.array(coords2) - np.array(coords)
print(freq,diff)
# node1 = (coords - diff)
# node2 = (coords2 + diff)
# in_map1 = check_in_map(node1,l)
# in_map2 = check_in_map(node2,l)
# if in_map1 and node1.tolist() not in nodes:
# nodes.append(node1.tolist())
# if in_map2 and node2.tolist() not in nodes :
# nodes.append(node2.tolist())
# print("nodes",node1,node2)
# print("list nodes", nodes)
k = 1
in_map = True
while in_map:
node = coords-k*diff
in_map = check_in_map(node,l)
if in_map and node.tolist() not in nodes:
nodes.append(node.tolist())
k+=1
in_map = True
k = 0
while in_map:
node = coords+k*diff
in_map = check_in_map(node,l)
if in_map and node.tolist() not in nodes:
nodes.append(node.tolist())
k+=1
print(len(nodes))