Elementary cellular automaton: Difference between revisions

Content added Content deleted
(Added Algol 68)
(Added 11l)
Line 17: Line 17:
* [http://natureofcode.com/book/chapter-7-cellular-automata Cellular automata (natureofcode.com)]
* [http://natureofcode.com/book/chapter-7-cellular-automata Cellular automata (natureofcode.com)]
<br><br>
<br><br>

=={{header|11l}}==
{{trans|Nim}}

<lang 11l>V SIZE = 32
V LINES = SIZE I/ 2
V RULE = 90

F ruleTest(x)
R I :RULE [&] (1 << (7 [&] x)) != 0 {1} E 0

F bitVal(s, bit)
R I (s >> bit) [&] 1 != 0 {1} E 0

F evolve(&s)
V t = 0
t [|]= ruleTest((bitVal(s, 0) << 2) [|] (bitVal(s, :SIZE - 1) << 1) [|] bitVal(s, :SIZE - 2)) << (:SIZE - 1)
t [|]= ruleTest((bitVal(s, 1) << 2) [|] (bitVal(s, 0) << 1) [|] bitVal(s, :SIZE - 1))
L(i) 1 .< :SIZE - 1
t [|]= ruleTest((bitVal(s, i + 1) << 2) [|] (bitVal(s, i) << 1) [|] bitVal(s, i - 1)) << i
s = t

F show(state)
L(i) (:SIZE - 1 .. 0).step(-1)
print(‘ *’[bitVal(state, i)], end' ‘’)
print()

V state = 1 << LINES
print(‘Rule ’RULE)
L 1..LINES
show(state)
evolve(&state)</lang>

{{out}}
<pre>
Rule 90
*
* *
* *
* * * *
* *
* * * *
* * * *
* * * * * * * *
* *
* * * *
* * * *
* * * * * * * *
* * * *
* * * * * * * *
* * * * * * * *
* * * * * * * * * * * * * * * *
</pre>


=={{header|Ada}}==
=={{header|Ada}}==