Added old 2022 AoC solves

This commit is contained in:
2023-12-09 22:06:15 +01:00
parent be08eff4ed
commit d3bd335e2b
14 changed files with 502 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
import sys
import numpy as np
import pprint, string
arr = []
alpha=list(string.ascii_letters)
values=[]
with open(sys.argv[1]) as f:
for l in f:
line=l.split()[0]
first, second = line[:len(line)//2],line[len(line)//2:]
shared=list(set(first)&set(second))[0]
index=alpha.index(shared)+1
values.append(index)
arr.append([first,second,shared,int(index)])
#pprint.pprint(arr)
print(sum(values))
+21
View File
@@ -0,0 +1,21 @@
import sys, pprint, string
arr = []
alpha=list(string.ascii_letters)
values_part1=[]
values_part2=[]
with open(sys.argv[1]) as f:
for l in f:
line=l.split()[0]
first, second = line[:len(line)//2],line[len(line)//2:]
shared=list(set(first)&set(second))[0]
index=alpha.index(shared)+1
values_part1.append(index)
arr.append([line,first,second,shared,int(index)])
print(sum(values_part1))
for i in range(0,len(arr),3):
shared=list(set(arr[i][0])&set(arr[i+1][0])&set(arr[i+2][0]))[0]
values_part2.append(int(alpha.index(shared)+1))
print(sum(values_part2))