adding to git what I have

This commit is contained in:
Aris
2024-12-09 10:59:37 +01:00
parent d2d7b76638
commit 6dace2f0c1
4 changed files with 131 additions and 0 deletions

39
2024/08/08.py Normal file
View 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))))

50
2024/08/input08.txt Normal file
View File

@@ -0,0 +1,50 @@
...........6.b....................................
........6................8........................
..Y.......................................o.......
....V...j............B.............c..............
............8.........X.......L...................
.....j..v6.......3.L..................c...........
..Mj.....p3.......b........Z....................J.
..........M...X...................................
V..............v......p.........Z.........c.......
..............3...................................
.......V......U3.............c....................
..........b..v.M.U8...............................
..........j........8.....................J........
..........Y......q........LH..Z...D...........y...
..2Y........PX......6..................BQ.........
...0.Y...............XP...........w...............
.........U.......2...............oH.y.............
0..............9........U.........................
...........P..............W.......z...Oy..........
...................t...p.W..o.............Q.......
.....S.................t.....Q....B...............
S.k..................V..W...p.......H...O......m..
....S.h................W.......................O..
..h..P.2.............Z.............J..............
.........k.......5v.......q...t.s.................
.....Q.....h..........................J...B.......
........0.........l...............................
.S................................................
.............................M....................
2..................e.....o.....y..................
................k.................................
......4......k....t...s.q.........................
.4.......................q........................
.......................z....E.....................
.............0.....d..............................
7..........D........z.............................
.......D..5......7..9.............................
......5..................E........................
D..............K......d..9E..........w.....1..C...
.......K..x.........d....s...........l............
........7......................u...C..............
..K........x..............9..C...u................
4..............s.........................l...T..w.
.......5.....7..................m......T......1...
...........................E...z.m................
......................................u...C.......
.............................em...................
..............................................T...
....................x.......................e.....
.............................1e....w....l.........

41
2024/09/09.py Normal file
View File

@@ -0,0 +1,41 @@
import copy
def checksum(diskdump):
out = 0
for i in range(0,len(diskdump)):
if diskdump[i] == ".":
return out
else:
out += diskdump[i]*i
def abstToDump(abst):
dump = []
flag = True
i = 0
for a in abst:
for j in range(0,int(a)):
dump.append(i if flag else -1)
flag = not flag
i += 1 if not flag else 0
return dump
def orderDump(dump):
arr = ["."]*len(dump)
i = 0
for a in dump:
if a == -1:
if dump[-1] != -1:
arr[i] = dump[-1]
i += 1
else:
pass
dump.pop(-1)
else:
arr[i] = a
i += 1
return arr
with open("input09.txt","r") as f:
dump = abstToDump(f.read())
order = orderDump(copy.deepcopy(dump))
print(checksum(order))

1
2024/09/input09.txt Normal file

File diff suppressed because one or more lines are too long