15-2 noch rechnen
This commit is contained in:
44
15/15-2.py
44
15/15-2.py
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user