day 22, optimized for codon
This commit is contained in:
parent
6081f917c0
commit
2cb6b3a793
|
@ -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)
|
|
@ -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()))
|
Loading…
Reference in New Issue