One-dimensional cellular automata: Difference between revisions

Content added Content deleted
Line 15: Line 15:
1'''1'''0 -> 1 # Needs one neighbour to survive
1'''1'''0 -> 1 # Needs one neighbour to survive
1'''1'''1 -> 0 # Starved to death.
1'''1'''1 -> 0 # Starved to death.

=={{header|8th}}==
<lang forth>
\ one-dimensional automaton

\ direct map of input state to output state:
{
" " : 32,
" #" : 32,
" # " : 32,
" ##" : 35,
"# " : 32,
"# #" : 35,
"## " : 35,
"###" : 32,
} var, lifemap

: transition \ s ix (r:s') -- (r:s')
>r dup r@ n:1- 3 s:slice
lifemap @ swap caseof
r> swap r@ -rot s:! >r ;

\ run over 'state' and generate new state
: gen \ s -- s'
clone >r
dup s:len 2 n:-
' transition 1 rot loop
drop r> ;

: life \ s -- s'
dup . cr gen ;

" ### ## # # # # # " ' life 10 times
bye

</lang>


=={{header|ACL2}}==
=={{header|ACL2}}==