Skip to content

Instantly share code, notes, and snippets.

@jvkersch
Last active August 4, 2020 16:31
Show Gist options
  • Save jvkersch/5e96c9ec31e2dfb1470a4cbddaf4c942 to your computer and use it in GitHub Desktop.
Save jvkersch/5e96c9ec31e2dfb1470a4cbddaf4c942 to your computer and use it in GitHub Desktop.
# Conway's famed FRACTRAN program to compute prime numbers.
# See https://en.wikipedia.org/wiki/FRACTRAN
def apply(num, prog):
while True:
for f, d in prog:
if num*f % d == 0:
yield (num := num*f // d)
break
else:
return num
conway = [
(17, 91), (78, 85), (19, 51), (23, 38), (29, 33), (77, 29), (95, 23),
(77, 19), (1, 17), (11, 13), (13, 11), (15, 2), (1, 7), (55, 1),
]
for f in apply(2, conway):
ilog2 = f.bit_length() - 1
if 2**ilog2 == f:
print(ilog2)
@shandhilyatushar
Copy link

Hey Joris, can you give your email id? Need some help on hsmmlearn code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment