Here's a simple command for listing simple cellular automata. Even among these (linear, each cell has 2 neghbours and 2 states), there are some interesting ones. This one will print 230 different ones.

perl -e 'for$r(0..511){$t=$/;@s=((0)x40,1,($r&1)x39); for(1..28){@s=map($r>>(8-4*$s[$_-1]-2*$s[$_]-$s[$_+1])&1, 1..78);unshift@s,$s[0];push@s,$s[-1];$t.=join"",map((".", "#")[$_],@s),$/;};$h{$t}.=sprintf"%03x ",$r;};print$h{$_}, $_ while$_=each%h;' | less

Ps: s/28/$L-2/e if your screen has $L lines; mine has 30.

Replies are listed 'Best First'.
Re: cellular automata
by simonm (Vicar) on Nov 02, 2003 at 20:12 UTC
    Or for only $44.95 plus shipping and handling, you can buy the hardcover edition put out by Stephen Wolfram...

      I got it the week it came out... and I'm still not through it entirely. I've been impressed with parts of it. (Though not his writing style which "in the end" repeats a certain three word phrase far too much.)

      I've always been interested in CAs. When I was in college, I wrote a little set of programs for exploring the set of 1 dimensional CAs that Wolfram describes as "totalistic cellular automata whose rules involve nearest and next-nearest neighbors, and where each cell has two possible colors." The representation of such a ruleset can be contained in 32 bits... rather convenient for C.

      I wrote a command line program in C that used GD to create gifs of these beasts and a little CGI to call it. I could pick a rule at random or enter its number and it would display a gif created from random starting conditions. At the same time, I'd create 32 smaller gifs each made from a 1 bit change in the ruleset, and those surrounded the main image. I could click on any of these "mutations" to make that one the main image and cause its "mutations" to be drawn. This gave me a convenient way to visually explore the space.¹

      I really should see if I can find that stuff. I'm sure I've got it sitting on an old zip disk somewhere. I should probably get around to burning those anyway.

      1. I think I got the idea from some third-party texture tool for photoshop I saw a friend of mine use. Probably one of the Kai (sp?) tools.

      -sauoq
      "My two cents aren't worth a dime.";
      

        As you can see, these cellular automata I calculated can be represented by 9 bits (8 for rules + 1 for starting pattern).

        Actually, 1/4 of these automata are generated a similar way in one of the examples of Mathematica. My solution is not much more difficult to write, but it needs nothing but Perl.

        Question: Is there an easy way to do this with strings and substitutions (or bitwise string ops) instead of arrays and map? Is that faster?

        Update 2012-12-16: see also Game of life ran by unpack function.

Re: cellular automata
by YuckFoo (Abbot) on Nov 03, 2003 at 22:41 UTC
    There are also cool patterns when you randomize the starting values. I did it this way.

    YuckFoo