adding to git what I have
This commit is contained in:
39
2024/08/08.py
Normal file
39
2024/08/08.py
Normal file
@@ -0,0 +1,39 @@
|
||||
def ptAdd(pt1,pt2):
|
||||
return [pt1[0]+pt2[0],pt1[1]+pt2[1]]
|
||||
|
||||
def ptSub(pt1,pt2):
|
||||
return [pt1[0]-pt2[0],pt1[1]-pt2[1]]
|
||||
|
||||
def antennae(arr):
|
||||
out = {}
|
||||
for i in range(0,len(arr)):
|
||||
for j in range(0,len(arr[i])):
|
||||
if arr[i][j] != ".":
|
||||
if arr[i][j] in out:
|
||||
out[arr[i][j]].append([i,j])
|
||||
else:
|
||||
out[arr[i][j]] = [[i,j]]
|
||||
return out
|
||||
|
||||
def antinodes(antennae):
|
||||
out = []
|
||||
for a in antennae:
|
||||
for i in range(0,len(antennae[a])):
|
||||
for j in range(1,len(antennae[a])):
|
||||
pt1 = antennae[a][i]
|
||||
pt2 = antennae[a][j]
|
||||
an1 = ptAdd(pt1,ptSub(pt1,pt2))
|
||||
an2 = ptAdd(pt2,ptSub(pt2,pt1))
|
||||
if an2 not in out and an2[0] >= 0 and an2[1] >= 0 and an2[0] < 50 and an2[1] < 50:
|
||||
out.append(an2)
|
||||
if an1 not in out and an1[0] >= 0 and an1[1] >= 0 and an1[0] < 50 and an1[1] < 50:
|
||||
out.append(an1)
|
||||
return out
|
||||
|
||||
arr = []
|
||||
with open("input08.txt") as file:
|
||||
for line in file:
|
||||
arr.append([])
|
||||
for a in line[:-1]:
|
||||
arr[-1].append(a)
|
||||
print(len(antinodes(antennae(arr))))
|
||||
Reference in New Issue
Block a user