One-dimensional cellular automata: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 4,841: | Line 4,841: | ||
______##________________________ |
______##________________________ |
||
</pre> |
</pre> |
||
=={{header|Yabasic}}== |
|||
{{trans|Locomotive_Basic}} |
|||
<lang Yabasic>10 n=10:READ w:DIM x(w+1),x2(w+1):FOR i=1 to w:READ x(i):NEXT |
|||
20 FOR k=1 TO n |
|||
30 FOR j=1 TO w |
|||
40 IF x(j) THEN PRINT "#"; ELSE PRINT "_"; END IF |
|||
50 IF x(j-1)+x(j)+x(j+1)=2 THEN x2(j)=1 ELSE x2(j)=0 END IF |
|||
60 NEXT:PRINT |
|||
70 FOR j=1 TO w:x(j)=x2(j):NEXT |
|||
80 NEXT |
|||
90 DATA 20,0,1,1,1,0,1,1,0,1,0,1,0,1,0,1,0,0,1,0,0</lang> |
|||
Other solution |
|||
<lang Yabasic>start$ = "0,1,1,1,0,1,1,0,1,0,1,0,1,0,1,0,0,1,0,0" |
|||
dim x$(1) |
|||
for k = 1 to 10 |
|||
n = token(start$, x$(), ",") |
|||
redim x$(n+1) |
|||
start$ = "" |
|||
for j = 1 to n |
|||
if val(x$(j)) then print "#"; else print "_"; end if |
|||
test = abs(val(x$(j-1)) + val(x$(j)) + val(x$(j+1)) = 2) |
|||
start$ = start$ + str$(test) + "," |
|||
next j |
|||
print |
|||
next k</lang> |
|||
=={{header|zkl}}== |
=={{header|zkl}}== |