From 2cb6b3a7935a9e9f280672036de26a0a225a36d5 Mon Sep 17 00:00:00 2001 From: setop Date: Tue, 24 Dec 2024 00:52:05 +0100 Subject: [PATCH] day 22, optimized for codon --- d22/part1.py | 15 +++++++++++++++ d22/part2.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 d22/part1.py create mode 100644 d22/part2.py diff --git a/d22/part1.py b/d22/part1.py new file mode 100644 index 0000000..0e8d696 --- /dev/null +++ b/d22/part1.py @@ -0,0 +1,15 @@ +import sys + +mask = 16777216-1 +def ng(n:int): + n ^= (n << 6) & mask + n ^= (n >> 5) & mask + n ^= (n << 11) & mask + return n + +ans = 0 +for x in = map(int,sys.stdin.read().strip().split('\n')): + for _ in range(2000): + x = ng(x) + ans += x +print(ans) diff --git a/d22/part2.py b/d22/part2.py new file mode 100644 index 0000000..db48e73 --- /dev/null +++ b/d22/part2.py @@ -0,0 +1,28 @@ +import sys + +mask = 16777216-1 +def ng(n:int) -> int: + n ^= (n << 6) & mask + n ^= (n >> 5) & mask + n ^= (n << 11) & mask + return n + +ranges = dict() +for seed in map(int,sys.stdin.read().strip().split('\n')): + visited = set() + pseed = seed % 10 + key = 0 + for i in range(2000): + nextSeed = ng(seed) + nseed = nextSeed %10 + change = 9 + nseed - pseed + key = (key * 19 + change) % 130321 + if i>2: + if key not in visited: + if key not in ranges: + ranges[key] = 0 + ranges[key] += nseed + visited.add(key) + seed = nextSeed + pseed = nseed +print(max(ranges.values()))