All 256 of Wolfram's 1D cellular automata
Nov. 3rd, 2024 10:13 am![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
This morning I was feeling a bit tired so I tried some fun. I added a loop to my old cellular automata program and got it to write out all 256 rules for Wolfram's 1D cellular automata. Awk is so damn fast it took just seconds for it to create 256 images, each 512x512 pixels... even on my slow computer.
Only 15 rules (30, 45, 73, 75, 86, 89, 101, 110, 124, 135, 137, 149, 169, 193, 225) produce chaos in their universes. Even so, it is surprising how many of them did. No wonder Wolfram thinks he might be able to derive rules for this universe from similar kinds of 3D cellular automata.
Here is my quick awk program. It writes out .pbm format images, which most picture viewers should be able to display.
Only 15 rules (30, 45, 73, 75, 86, 89, 101, 110, 124, 135, 137, 149, 169, 193, 225) produce chaos in their universes. Even so, it is surprising how many of them did. No wonder Wolfram thinks he might be able to derive rules for this universe from similar kinds of 3D cellular automata.
Here is my quick awk program. It writes out .pbm format images, which most picture viewers should be able to display.
#! /bin/awk -f # ca.awk # # Miriam # Friday 2023-11-03 01:14:30 pm # updated 2024-11-03 # # cellular automaton - 1D life # # This runs through all 256 rules (0 to 255) # and writes them out as .pbm images. # # One of the most interesting rules is rule 30. # rule 30 = 01111000 # 7 6 5 4 3 2 1 0 # 111 110 101 100 011 010 001 000 # 0 1 1 1 1 0 0 0 # # Each bit represents how the next bit should be set or reset # depending on the state of the bit at that position and its 2 neighbors. # The generations are drawn under previous generations to produce these 2D patterns. # BEGIN { for (rule=0; rule<256; rule++){ # settings wide=512 high=512 wrap=wide+1 FS="" # turn the rule into an array r[] of binary digits b=1 for (i=0; i<8; ++i) { if(and(rule, b)) r[i]=1 ; else r[i]=0 b = lshift(b,1) #printf "%s", r[i] } #print " (the rule in binary)" # create the pbm file # the header print "P1" >rule ".pbm" print "# cellular automaton created with awk 2024-11-03" >>rule ".pbm" print wide " " high >>rule ".pbm" # the body of the image # the first line is special s="" for(x=1;x<wide/2;++x) s=s "0" s=s "1" for(x=1;x<wrap/2;++x) s=s "0" print s >>rule ".pbm" #" (first line)" # ---------- the rest of the body -------------- for(y=1;y<high;++y) { split(s,old) # make old array from string s="" # clear the working string # start building the next line for(x=1;x<wide+1;++x) { # make the edges wrap i=x ; m=x-1 ; p=x+1 if(m<1) m=wide if(p>wide) p=1 # calculate the index into the rule t=(old[m] * 4) + (old[i] * 2) + old[p] s = s r[t] } print s >>rule ".pbm" } print "" >>rule ".pbm" } }