Last active
August 4, 2020 16:31
-
-
Save jvkersch/5e96c9ec31e2dfb1470a4cbddaf4c942 to your computer and use it in GitHub Desktop.
This file contains 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
# 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Joris, can you give your email id? Need some help on hsmmlearn code.