Last active
December 15, 2023 06:13
-
-
Save vjeranc/4e55dd28fb8e618ab416274fc4d86e4e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def chsh(s): | |
hsh = 0 | |
for c in s: | |
hsh += ord(c) | |
hsh *= 17 | |
hsh %= 256 | |
return hsh | |
hshsum = 0 | |
bx = [dict() for _ in range(256)] | |
for s in input().split(','): | |
hshsum += chsh(s) # part 1 | |
match s.split('='): | |
case [l, f]: | |
bx[chsh(l)][l] = int(f) | |
case [l]: | |
bx[chsh(l[:-1])].pop(l[:-1], 0) | |
print(hshsum) | |
print(sum(i*j*b[h] for i, b in enumerate(bx, 1) for j, h in enumerate(b, 1))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment