Browse Source

Day 15.

master
Chris Smith 6 years ago
parent
commit
73f4b855c5
2 changed files with 18 additions and 0 deletions
  1. 16
    0
      15.py
  2. 2
    0
      data/15.txt

+ 16
- 0
15.py View File

@@ -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)))}')

+ 2
- 0
data/15.txt View File

@@ -0,0 +1,2 @@
1
+Generator A starts with 699
2
+Generator B starts with 124

Loading…
Cancel
Save