[Edu-sig] Another idea of Conway
Gregor Lingl
gregor.lingl at aon.at
Mon Aug 31 22:52:33 CEST 2009
Hi all,
on vacation in the Tyrolean Alps one evening
I've found the time to implement another (I assume
less well known) idea of John Conway.
Just for fun.
from fractions import Fraction
fracs = [Fraction(f) for f in
"17/91 78/85 19/51 23/38 29/33 77/29 95/23 77/19 1/17 11/13 13/11
15/14 15/2 55/1".split()]
def fracgame():
z = Fraction(2,1)
while True:
for f in fracs:
n = z * f
if n.denominator == 1:
break
yield int(n)
z = n
def pow2(z):
n = 0
while z % 2 == 0:
n += 1
z //= 2
return (z == 1) * n
def what():
fg = fracgame()
while True:
z = next(fg)
n = pow2(z)
if n != 0:
yield n
what = what()
print(next(what))
print(next(what))
# the following will take 1 or 2 minutes
##w = 0
##while w < 100:
## w = next(what)
## print(w)
Comments or discussion may follow when
I'm back to Vienna.
All the best,
Gregor
More information about the Edu-sig
mailing list