10 w%=10:h%=10:size%=w%*h%
15 dim k%(size%+1): dim l%(size%+1)
20 k%(0)=1:k%(1)=1:k%(2)=1:g%=1:inlife%=3

30 cls
35 for i%=0 to size%-1
40 if k%(i%) <> 0 then plot i%-((i%/h%)*w%), i%/h%
50 next i%
60 for i%=0 to size%-1
70 if k%(i%) = 0 then gosub 1000
80 if k%(i%) <> 0 then gosub 2000
90 next i%
100 gosub 4000

101 ds str$(g%), 100, 0:rem generations
102 ds str$(inlife%), 100, 20:rem run!
103 repaint:sleep 500
104 if inlife%=0 then ds "budda in panic", 0, 50:repaint:sleep 2000:end
105 g% = g%+1:inlife%=0
110 goto 30

1000 gosub 3000
1010 if q%=3 then l%(i%)=1
1020 return

2000 gosub 3000
2010 if q% < 2 or q% > 3 then l%(i%)=0
2020 if q%=2 or q%=3 then l%(i%)=1
2030 return

2999 rem calc friends
3000 a% = i%-w%-1
3001 b% = i%-w%
3002 c% = i%-w%+1
3003 m% = i%-1
3004 n% = i%
3005 p% = i%+1
3006 x% = i%+w%-1
3007 y% = i%+w%
3008 z% = i%+w%+1
3010 if a%<0 then a%=size%+a%
3015 if b% < 0 then b%=size%+b%
3020 if c% < 0 then c%=size%+c%
3025 if m%<0 then m%=size%+m%
3030  if p%>=size% then p%=p%-size%
3040 if x%>=size% then x%=x%-size%
3050 if y%>=size% then y%=y%-size%
3060 if z%>=size% then z%=z%-size%

3070 q%=k%(a%) + k%(b%) + k%(c%) + k%(m%) + k%(n%) + k%(p%) + k%(x%) + k%(z%) + k%(y%)
3080 return

3999 rem copy array
4000 for i%=0 to size%-1
4010 k%(i%)=l%(i%)
4011 inlife% = inlife%+l%(i%)
4020 next i%
4030 return