15-2 fertig

This commit is contained in:
2023-12-15 16:45:15 +01:00
parent c3a07f43df
commit 240685a703
2 changed files with 11 additions and 9 deletions

View File

@@ -3,7 +3,7 @@
data = []
# parse input
input_file = open("input-ex1", "r")
input_file = open("input", "r")
pattern = []
for line in input_file:
for value in line.rstrip().split(","):
@@ -12,12 +12,12 @@ input_file.close()
def get_hash(val):
h = 0
hav = 0
for b in val:
h += ord(b)
h *= 17
h %= 256
return h
hav += ord(b)
hav *= 17
hav %= 256
return hav
hashsum = 0
@@ -56,8 +56,10 @@ for value in data:
boxes[h] = [value]
print(boxes)
solution=0
solution = 0
for key in boxes.keys():
for k in range(len(boxes[key])):
pass
print(key+1, k+1, int(boxes[key][k].split("=")[1]))
solution += ((key+1) * (k+1) * int(boxes[key][k].split("=")[1]))
print("Solution", solution)