This commit is contained in:
basicbonobo 2023-12-15 07:04:22 +01:00
parent 133fc9a5f6
commit f4dbdb5202
1 changed files with 26 additions and 1 deletions

View File

@ -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)))