Maria Droujkova schrieb:
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!

Unfortunately I don't know of any. There is a chapter on Fractran in

Julian Havil: Nonplussed!: Mathematical Proof of Implausible Ideas
http://www.amazon.com/Nonplussed-Mathematical-Proof-Implausible-Ideas/dp/0691120560

It contains a nice proof of the fact that that 'fractran-program' calculates exactly the primes. Although perhaps "more accessible" it still assumes some computer science background.

And, yes, it's fun. But as it happens so often with fun, it's useless - in contrast to cooking ;-) ,
which may be fun also, though.

You have to calculate 281 integers to arrive at 32, which delivers the prime 5 and
710 integers to arrive at the next prime: 7

Best wishes
Gregor

P.S.: I like your homepage. Think I should register to find out more
about what it's all about.

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.li...@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@python.org
http://mail.python.org/mailman/listinfo/edu-sig

_______________________________________________
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


_______________________________________________
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig

Reply via email to