Skip to content

Instantly share code, notes, and snippets.

@wimglenn
Last active May 20, 2021 03:27
Show Gist options
  • Save wimglenn/105afcf22e186cb4753555e5c38e2d64 to your computer and use it in GitHub Desktop.
Save wimglenn/105afcf22e186cb4753555e5c38e2d64 to your computer and use it in GitHub Desktop.
original implementation
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