One-dimensional cellular automata: Difference between revisions
Content deleted Content added
→{{header|C++}}: Actually you don't need a case statement at all here |
No edit summary |
||
Line 903: | Line 903: | ||
<lang javascript>alert(caStep([0,1,1,1,0,1,1,0,1,0,1,0,1,0,1,0,0,1,0,0]));</lang> |
<lang javascript>alert(caStep([0,1,1,1,0,1,1,0,1,0,1,0,1,0,1,0,0,1,0,0]));</lang> |
||
shows an alert with "0,1,0,1,1,1,1,1,0,1,0,1,0,1,0,0,0,0,0,0". |
shows an alert with "0,1,0,1,1,1,1,1,0,1,0,1,0,1,0,0,0,0,0,0". |
||
=={{header|Liberty BASIC}}== |
|||
<lang lb>' [RC] 'One-dimensional cellular automata' |
|||
global rule$, state$ |
|||
rule$ ="00010110" ' Rule 22 decimal |
|||
state$ ="0011101101010101001000" |
|||
for j =1 to 20 |
|||
oldState$ =state$ |
|||
state$ ="0" |
|||
for k =2 to 32 |
|||
NHood$ =mid$( oldState$, k -1, 3) ' pick 3 char neighbourhood and turn binary string to decimal |
|||
vNHood =0 |
|||
for kk =3 to 1 step -1 |
|||
vNHood =vNHood +val( mid$( NHood$, kk, 1)) *2^( 3 -kk) |
|||
next kk |
|||
' .... & use it to index into rule$ to find appropriate new value |
|||
state$ =state$ +mid$( rule$, vNHood +1, 1) |
|||
next k |
|||
print state$ |
|||
next j |
|||
end</lang> |
|||
=={{header|Logo}}== |
=={{header|Logo}}== |