-
-
Save pawlos/fec8f99521de483a3e3d3fd1127d6cef to your computer and use it in GitHub Desktop.
Solution to Day 15: Dueling Generators - part 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#aoc_d15.py | |
valueA = 516 | |
def genA(): | |
global valueA | |
while True: | |
valueA = (valueA * 16807) % 2147483647 | |
if valueA % 4 == 0: | |
break | |
return valueA | |
valueB = 190 | |
def genB(): | |
global valueB | |
while True: | |
valueB = (valueB * 48271) % 2147483647 | |
if valueB % 8 == 0: | |
break | |
return valueB | |
cnt = 0 | |
_2to16 = 2 ** 16 - 1 | |
for i in range(5000000): | |
a = genA() & _2to16 | |
b = genB() & _2to16 | |
if (a == b): | |
cnt += 1 | |
#print a,",", b | |
#print "A: ",genA(), "B: ",genB() | |
print cnt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment