15b
This commit is contained in:
parent
133fc9a5f6
commit
f4dbdb5202
27
fünfzehn.py
27
fünfzehn.py
|
@ -5,4 +5,29 @@ from useful import *
|
|||
def hush(s):
|
||||
return reduce(lambda a, b: (a+ord(b))*17%256, s, 0)
|
||||
|
||||
print(sum(hush(s) for s in open(0).read().strip().split(',')))
|
||||
steps = open(0).read().strip().split(',')
|
||||
|
||||
print(sum(hush(s) for s in steps))
|
||||
|
||||
boxen = [deque() for _ in range(256)]
|
||||
|
||||
for s in steps:
|
||||
if s[-1] == '-':
|
||||
id = s[:-1]
|
||||
box = boxen[hush(id)]
|
||||
for i in range(len(box)):
|
||||
if box[i][0] == id:
|
||||
del box[i]
|
||||
break
|
||||
else:
|
||||
id, vstr = s.split('=')
|
||||
box = boxen[hush(id)]
|
||||
val = int(vstr)
|
||||
for i in range(len(box)):
|
||||
if box[i][0] == id:
|
||||
box[i][1] = val
|
||||
break
|
||||
else:
|
||||
box.append([id, val])
|
||||
|
||||
print(sum((i+1) * (j+1) * foc for i, b in enumerate(boxen) for j, (s, foc) in enumerate(b)))
|
||||
|
|
Loading…
Reference in New Issue