Hacker News new | past | comments | ask | show | jobs | submit login
FRACTRAN - the esoteric programming language invented by John H Conway (wikipedia.org)
4 points by robinhouston on Oct 17, 2011 | hide | past | favorite | 1 comment



That was neat. Here's an implementation in Python:

    # Python implementation of Conway's prime formula for FRACTRAN
    # The output is the sequence A034785.
    
    from fractions import Fraction as F
    
    terms = [F(17, 91), F(78, 85), F(19, 51), F(23, 38), F(29, 33),
             F(77, 29), F(95, 23), F(77, 19), F(1, 17), F(11, 13),
             F(13, 11), F(15, 14), F(15, 2), F(55, 1)]
    
    n = 2
    print n
    
    while 1:
        for i, f in enumerate(terms):
            fn = f * n
            if fn.denominator == 1:
                n = fn.numerator
                print n
                break
        else:
            break




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: