2024: d22: ex1: add solution

This commit is contained in:
Bruno BELANYI 2024-12-22 00:50:22 -05:00
parent 139069f251
commit fbc63b138f

35
2024/d22/ex1/ex1.py Executable file
View file

@ -0,0 +1,35 @@
#!/usr/bin/env python
import sys
def solve(input: str) -> int:
def monkey_hash(seed: int) -> int:
MASK = (1 << 24) - 1
seed ^= seed << 6
seed &= MASK
seed ^= seed >> 5
seed &= MASK
seed ^= seed << 11
seed &= MASK
return seed
def run_rounds(seed: int) -> int:
for _ in range(2000):
seed = monkey_hash(seed)
return seed
seeds = [int(n) for n in input.splitlines()]
return sum(map(run_rounds, seeds))
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()