15-2 noch rechnen

This commit is contained in:
2023-12-15 16:00:30 +01:00
parent 619c996b9f
commit c3a07f43df
2 changed files with 41 additions and 5 deletions

2
.idea/misc.xml generated
View File

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

View File

@@ -13,7 +13,7 @@ input_file.close()
def get_hash(val):
h = 0
for b in value:
for b in val:
h += ord(b)
h *= 17
h %= 256
@@ -21,7 +21,43 @@ def get_hash(val):
hashsum = 0
boxes = {}
for value in data:
print(value, get_hash(value))
hashsum += get_hash(value)
print("Hashsumme:", hashsum)
if value.count("-") == 1:
value = value.replace("-", "=")
h = get_hash(value[:-1])
if h in boxes.keys():
lin = boxes[h]
x = -1
for j in range(len(lin)):
if lin[j].startswith(value):
x = j
if x != -1:
lin.pop(x)
if len(lin) == 0:
boxes.pop(h)
else:
boxes[h] = lin
else:
hv = value.split("=")[0]
h = get_hash(hv)
ersetzt = False
if h in boxes.keys():
linsen = boxes[h]
for i in range(len(linsen)):
if linsen[i].startswith(hv+"="):
linsen[i] = value
ersetzt = True
if not ersetzt:
linsen.append(value)
boxes[h] = linsen
else:
boxes[h] = [value]
print(boxes)
solution=0
for key in boxes.keys():
for k in range(len(boxes[key])):
pass