Conway's Game of Life: Difference between revisions
adding maxima
m (add empty line in test code to improve readability) |
Capra Hircus (talk | contribs) (adding maxima) |
||
Line 3,067:
..###
</pre>
=={{header|Maxima}}==
<lang maxima>life(A) := block(
[p, q, B: zerofor(A), s],
[p, q]: matrix_size(A),
for i thru p do (
for j thru q do (
s: 0,
if j > 1 then s: s + A[i, j - 1],
if j < q then s: s + A[i, j + 1],
if i > 1 then (
s: s + A[i - 1, j],
if j > 1 then s: s + A[i - 1, j - 1],
if j < q then s: s + A[i - 1, j + 1]
),
if i < p then (
s: s + A[i + 1, j],
if j > 1 then s: s + A[i + 1, j - 1],
if j < q then s: s + A[i + 1, j + 1]
),
B[i, j]: charfun(s = 3 or (s = 2 and A[i, j] = 1))
)
),
B
)$
/* a glider */
L: matrix([[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])$
life(L);</lang>
=={{header|OCaml}}==
|