Last active
May 20, 2021 03:27
-
-
Save wimglenn/105afcf22e186cb4753555e5c38e2d64 to your computer and use it in GitHub Desktop.
original implementation
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 duel(a, b): | |
fa = 16807 | |
fb = 48271 | |
d = 0x7fffffff | |
count1 = 0 | |
a4 = [] | |
b8 = [] | |
for i in range(40000000): | |
a = (a * fa) % d | |
b = (b * fb) % d | |
a16 = a & 0xffff | |
b16 = b & 0xffff | |
count1 += a16 == b16 | |
if not a16 & 0b11: | |
a4.append(a16) | |
if not b16 & 0b111: | |
b8.append(b16) | |
while len(b8) < 5000000: | |
b = (b * fb) % d | |
b16 = b & 0xffff | |
if not b16 & 0b111: | |
b8.append(b16) | |
count2 = sum(a4[i] == b8[i] for i in range(5000000)) | |
return count1, count2 | |
assert duel(783, 325) == (650, 336) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment