Elementary cellular automaton: Difference between revisions

Content added Content deleted
No edit summary
Line 1,182: Line 1,182:
* * * * * * * *
* * * * * * * *
* * * * * * * * * * * * * * * *</lang>
* * * * * * * * * * * * * * * *</lang>

=={{header|MontiLang}}==
<lang MontiLang>30 VAR length .
35 VAR height .
FOR length 0 ENDFOR 1 0 ARR VAR list .
length 1 - VAR topLen .
FOR topLen 0 ENDFOR 1 ARR VAR topLst .

DEF getNeighbors
1 - VAR tempIndex .
GET tempIndex SWAP
tempIndex 1 + VAR tempIndex .
GET tempIndex SWAP
tempIndex 1 + VAR tempIndex .
GET tempIndex SWAP .
FOR 3 TOSTR ROT ENDFOR
FOR 2 SWAP + ENDFOR
ENDDEF

DEF printArr
LEN 1 - VAR stLen .
0 VAR j .
FOR stLen
GET j
TOSTR OUT .
j 1 + VAR j .
ENDFOR
|| PRINT .
ENDDEF

FOR height
FOR length 0 ENDFOR ARR VAR next .
1 VAR i .
FOR length
list i getNeighbors VAR last .
i 1 - VAR ind .
last |111| ==
IF : .
next 0 INSERT ind
ENDIF

last |110| ==
IF : .
next 1 INSERT ind
ENDIF

last |101| ==
IF : .
next 1 INSERT ind
ENDIF

last |100| ==
IF : .
next 0 INSERT ind
ENDIF

last |011| ==
IF : .
next 1 INSERT ind
ENDIF

last |010| ==
IF : .
next 1 INSERT ind
ENDIF

last |001| ==
IF : .
next 1 INSERT ind
ENDIF

last |000| ==
IF : .
next 0 INSERT ind
ENDIF
clear
i 1 + VAR i .
ENDFOR
next printArr .
next 0 ADD APPEND . VAR list .
ENDFOR</lang>


=={{header|Perl}}==
=={{header|Perl}}==