Created
December 15, 2017 07:06
-
-
Save redspider/4f2c27e3bf6b9e1f3bf13910bf961647 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def generator(start, factor, multiple = 1): | |
previous = start | |
while True: | |
n = previous * factor % 2147483647 | |
previous = n | |
if n % multiple == 0: | |
yield n | |
A = generator(116, 16807, 4) | |
B = generator(299, 48271, 8) | |
count = 0 | |
for i in range(0, 5000000): | |
count += next(A) & 0xffff == next(B) & 0xffff and 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment