25 lines
444 B
Text
25 lines
444 B
Text
step(M,p,f)={
|
|
my(m=matsize(M)[1],n=matsize(M)[2]);
|
|
matrix(m,n,i,j,
|
|
if(M[i,j]=="*",
|
|
" "
|
|
,
|
|
if(M[i,j]=="t",
|
|
my(nbr="t");
|
|
for(x=max(1,i-1),min(m,i+1),
|
|
for(y=max(1,j-1),min(n,j+1),
|
|
if(M[x,y]=="*",nbr="*";break(2))
|
|
)
|
|
);
|
|
if(random(1.)<f,"*",nbr)
|
|
,
|
|
if(random(1.)<p,"t"," ")
|
|
)
|
|
)
|
|
)
|
|
};
|
|
burn(n,p,f)={
|
|
my(M=matrix(n,n,i,j,if(random(2)," ","t")),N);
|
|
while(1,print(M=step(M,p,f)))
|
|
};
|
|
burn(5,.1,.03)
|