One-dimensional cellular automata: Difference between revisions
Content deleted Content added
Added C++ |
{{header|PureBasic}} |
||
Line 1,142:
Gen. 9: __##________________
</pre>
=={{header|PureBasic}}==
<lang PureBasic>EnableExplicit
Dim cG.i(21)
Dim nG.i(21)
Define.i n, Gen
DataSection
Data.i 0,1,1,1,0,1,1,0,1,0,1,0,1,0,1,0,0,1,0,0
EndDataSection
For n=1 To 20
Read.i cG(n)
Next
OpenConsole()
Repeat
Print("Generation "+Str(Gen)+":")
For n=1 To 20
Print(Str(cG(n)))
Next
Gen +1
PrintN("")
For n=1 To 20
If (cG(n)= 1 And (cG(n-1)+cg(n+1)=1)) Or (cG(n)= 0 And (cG(n-1)+cg(n+1)=2))
nG(n)=1
Else
nG(n)=0
EndIf
Next
Swap cG() , nG()
Until Gen > 9
PrintN("Press any key to exit"): Repeat: Until Inkey() <> ""</lang>
Output:
<pre>Generation 0:01110110101010100100
Generation 1:01011111010101000000
Generation 2:00110001101010000000
Generation 3:00110001110100000000
Generation 4:00110001011000000000
Generation 5:00110000111000000000
Generation 6:00110000101000000000
Generation 7:00110000010000000000
Generation 8:00110000000000000000
Generation 9:00110000000000000000
Press any key to exit</pre>
=={{header|Python}}==
|