|
@@ -0,0 +1,16 @@
|
|
1
|
+import itertools
|
|
2
|
+import operator
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+def gen(seed, factor, multiple=1):
|
|
6
|
+ value = seed
|
|
7
|
+ while True:
|
|
8
|
+ value = (value * factor) % 2147483647
|
|
9
|
+ if value % multiple == 0:
|
|
10
|
+ yield value & 65535
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+with open('data/15.txt', 'r') as file:
|
|
14
|
+ seeds = [int(line.strip().split()[-1]) for line in file.readlines()]
|
|
15
|
+ print(f'Part one: {sum(map(lambda t: t[0] == t[1], itertools.islice(zip(gen(seeds[0], 16807), gen(seeds[1], 48271)), 40_000_000)))}')
|
|
16
|
+ print(f'Part two: {sum(map(lambda t: t[0] == t[1], itertools.islice(zip(gen(seeds[0], 16807, 4), gen(seeds[1], 48271, 8)), 5_000_000)))}')
|