-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay15.py
More file actions
49 lines (40 loc) · 1.08 KB
/
Day15.py
File metadata and controls
49 lines (40 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Generator A starts with 277
# Generator B starts with 349
def generatorA(prev):
return prev * 16807 % 2147483647
def generatorB(prev):
return prev * 48271 % 2147483647
def generatorA2(prev):
while True:
prev = prev * 16807 % 2147483647
if not prev & 3:
return prev
def generatorB2(prev):
while True:
prev = prev * 48271 % 2147483647
if not prev & 7:
return prev
if __name__ == "__main__":
valA = 277
valB = 349
count = 0
for round in range(40*10**6):
if not round % 10**6 and round:
print(int(round/(10**6)))
valA = generatorA(valA)
valB = generatorB(valB)
if valA & 0xFFFF == valB & 0xFFFF:
count += 1
print("Part1:",count)
#part2
valA = 277
valB = 349
count = 0
for round in range(5*10**6):
if not round % 10**6 and round:
print(int(round/(10**6)))
valA = generatorA2(valA)
valB = generatorB2(valB)
if valA & 0xFFFF == valB & 0xFFFF:
count += 1
print("Part2:",count)