I’d like to claim this is “one line of C”, but actually it’s 98
characters, which is more than a regulation 80-character punched card.

    char*s;main(int 
c,char**v){for(;;)for(s=v[1],puts(s),c=0;s[2];*s++=".##.###."[c&7],c=s[1]&1|c*2);}

It computes successive states of rule 110; it works like this:

    : kra...@inexorable:~/devel/inexorable-misc ; ./rule110  
................................##........................... | head -20
    ................................##...........................
    ...............................#.##..........................
    ..............................###.##.........................
    .............................#..##.##........................
    ............................####.##.##.......................
    ...........................#...##.##.##......................
    ..........................###.#.##.##.##.....................
    .........................#..####.##.##.##....................
    ........................####...##.##.##.##...................
    .......................#...##.#.##.##.##.##..................
    ......................###.#.####.##.##.##.##.................
    .....................#..####...##.##.##.##.##................
    ....................####...##.#.##.##.##.##.##...............
    ...................#...##.#.####.##.##.##.##.##..............
    ..................###.#.####...##.##.##.##.##.##.............
    .................#..####...##.#.##.##.##.##.##.##............
    ................####...##.#.####.##.##.##.##.##.##...........
    ...............#...##.#.####...##.##.##.##.##.##.##..........
    ..............###.#.####...##.#.##.##.##.##.##.##.##.........
    .............#..####...##.#.####.##.##.##.##.##.##.##........

If you try to run it without a command-line argument, it will crash.

As you can probably guess, both the state transition function and the
graphical output are encoded in the `".##.###."` string. If you
replace it with `v[2]`, then you can supply your own state transition
function. If you decide to use other characters for the display, make
sure that their low-order bits are different.

This software is available via

    git clone http://canonical.org/~kragen/sw/inexorable-misc.git

(or in <http://canonical.org/~kragen/sw/inexorable-misc>) in the file
`rule110.c`.

Like everything else posted to kragen-hacks without a notice to the
contrary, this software is in the public domain.

-- 
To unsubscribe: http://lists.canonical.org/mailman/listinfo/kragen-hacks

Reply via email to