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

2
.idea/misc.xml generated
View File

@@ -3,7 +3,7 @@
<component name="Black"> <component name="Black">
<option name="sdkName" value="Python 3.11 (AdventOfCode2023)" /> <option name="sdkName" value="Python 3.11 (AdventOfCode2023)" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" project-jdk-name="Python 3.10 (AdventOfCode2023)" project-jdk-type="Python SDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_21" project-jdk-name="Python 3.11 (AdventOfCode2023)" project-jdk-type="Python SDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

View File

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