I'm trying to model Conway's Game of Life and here's my code:

> f :=proc(a, b, c, d, e, f, g, h)

localalivecount;

alivecount := b+c+d+e+f+g+h;

ifa = 1andalivecount < 2thena := 0

elifa = 1and3 < alivecountthena := 1

elifa = 0andalivecount = 3thena := 1

end if;

end proc;

> run2dca :=proc(n::integer, f:: procedure, S0:: (list(list(numeric))), m::integer) local S, x, y, q, i, j;

S := [S0];

x := Array(0 .. n-1, 0 .. n-1, S0);

y := Array(0 .. n-1, 0 .. n-1);

forq to mdo

fori from 0 to n-1do

forj from 0 to n-1do

y[i][j] = f(x[i][j], x[i+1 mod n)][j], x[i-1 mod n)][j], x[i][j+1 mod n)], x[i][j-1 mod n], x[i+1 mod n)][j+1 mod n)], x[i+1 mod n)][j-1 mod n)], x[i-1 mod n)][j+1 mod n)], x[i-1 mod n)][j-1 mod n)])

end do;

end do;

S := [op(S), convert(y, list)];

x, y := y, x

end do;

S

end proc;

n:= number of rows/columns of the nxn list

f:= update function

S0 := 2 dimensional nxn list

m := number of iterations

Yet when I try and run my code:

> BLOCK := [[1,1],[1,1]];

> run2dca(2,f, BLOCK, 5);

Error, (in run2dca) bad index into Array

I get the above error, and I have no idea what it means. Any help would be appreciated

EDIT: I've narrowed down the error to this line of code, x := Array(0 .. n-1, 0 .. n-1, S0); I have no idea what is wrong thogh