Skip to content

Instantly share code, notes, and snippets.

@pawlos
Last active December 15, 2017 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawlos/0461352818500cd46b3183f8bbacc539 to your computer and use it in GitHub Desktop.
Save pawlos/0461352818500cd46b3183f8bbacc539 to your computer and use it in GitHub Desktop.
Solution to Day 15: Dueling Generators
#aoc_d15.py
valueA = 516
def genA():
global valueA
valueA = (valueA * 16807) % 2147483647
return valueA
valueB = 190
def genB():
global valueB
valueB = (valueB * 48271) % 2147483647
return valueB
cnt = 0
_2to16 = 2 ** 16 - 1
for i in range(40000000):
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