[Edu-sig] Another idea of Conway

Maria Droujkova droujkova at gmail.com
Sun Sep 13 16:59:51 CEST 2009


This language looks like a lot of fun. Especially given the fact none
of students coming to me for the first time (or their parents) can't
typically find any use of fractions beyond cooking, if that. Are there
some beginner, hands-on/visual or otherwise "more accessible" examples
for it? What fun!

Cheers,
Maria Droujkova
http://www.naturalmath.com

Make math your own, to make your own math.





On Sun, Sep 13, 2009 at 8:08 AM, Gregor Lingl <gregor.lingl at aon.at> wrote:
> Although my posting to this list seems to tend to become
> a somewhat autistic activity I'd like to reveal the 'mystery'
> behind the script below:
>
> http://esolangs.org/wiki/Fractran
> http://en.wikipedia.org/wiki/FRACTRAN
>
> Would writing a fractran interpreter in python be an interesting
> project for teaching CS? (My first try below allows for a lot of
> optimizations, e.g. not to use Fraction but resort to (long) ints.)
>
> Best wishes,
> Gregor
>
> Gregor Lingl schrieb:
>>
>> 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
>>
>> _______________________________________________
>> Edu-sig mailing list
>> Edu-sig at python.org
>> http://mail.python.org/mailman/listinfo/edu-sig
>>
> _______________________________________________
> Edu-sig mailing list
> Edu-sig at python.org
> http://mail.python.org/mailman/listinfo/edu-sig
>


More information about the Edu-sig mailing list