Last active
November 24, 2020 09:21
-
-
Save dlozeve/903c9d5dcb06f8165321154d100ef091 to your computer and use it in GitHub Desktop.
Rule 30 cellular automaton in Dyalog APL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
⎕io←0 | |
⍝ Stencil uses zero boundaries | |
r30←{(7-2⊥⍵)⌷(8⍴2)⊤30}⌺3 | |
⍝ Other version, slightly shorter but less legible | |
r30←{⊃30⊤⍨2⍴⍨1+2⊥⍵}⌺3 | |
⍝ Single alive cell initialization | |
init←(30⍴0),1,30⍴0 | |
' █'[↑{(r30⍣⍵)init}¨⍳30] | |
⍝ Random initialization | |
init←?79⍴2 | |
' █'[↑{(r30⍣⍵)init}¨⍳30] | |
⍝ Arbitrary 1D cellular automaton with cyclical boundaries | |
⍝ Left argument is the rule number | |
ca←{⊃¨⍺⊤⍨¨2⍴⍨¨1+2⊥↑¯1 0 1∘.⌽⊂⍵} | |
' █'[↑{((30∘ca)⍣⍵)(30⍴0),1,30⍴0}¨⍳30] | |
⍝ █ | |
⍝ ███ | |
⍝ ██ █ | |
⍝ ██ ████ | |
⍝ ██ █ █ | |
⍝ ██ ████ ███ | |
⍝ ██ █ █ █ | |
⍝ ██ ████ ██████ | |
⍝ ██ █ ███ █ | |
⍝ ██ ████ ██ █ ███ | |
⍝ ██ █ █ ████ ██ █ | |
⍝ ██ ████ ██ █ █ ████ | |
⍝ ██ █ ███ ██ ██ █ █ | |
⍝ ██ ████ ██ ███ ███ ██ ███ | |
⍝ ██ █ █ ███ █ ███ █ █ | |
⍝ ██ ████ ██ █ █ █████ ███████ | |
⍝ ██ █ ███ ████ █ ███ █ | |
⍝ ██ ████ ██ ███ ██ ██ █ ███ | |
⍝ ██ █ █ ███ █ ██ ███ ████ ██ █ | |
⍝ ██ ████ ██ █ ██████ █ █ ███ ████ | |
⍝ ██ █ ███ ████ ████ ███ ██ █ █ | |
⍝ ██ ████ ██ ███ █ ██ █ █ █ ███ ███ | |
⍝ ██ █ █ ███ █ ███ ██ █ ███ ██ █ █ █ █ | |
⍝ ██ ████ ██ █ ███ █ █ ████ █ █ ██ ██████ | |
⍝ ██ █ ███ ████ ██ █████ █ █████ █ █ █ | |
⍝ ██ ████ ██ ███ █ ██ █ █ ██ █ █████ ███ | |
⍝ ██ █ █ ███ █ ██ █ ████ ██ █ ██ ██ █ ██ █ | |
⍝ ██ ████ ██ █ ███ █ █ █ ███ ████ █ ██ █ ██ █ ████ | |
⍝ ██ █ ███ ████ ████ ██ ██ ███ █ █ ████ █ █ █ | |
⍝ ██ ████ ██ ███ █ ██ █ █ ███ █ ██ ████ ███ ██ ███ | |
⍝ Rule 110 | |
' █'[↑{((110∘ca)⍣⍵)60⍴(14⍴0),1}¨⍳30] | |
⍝ █ █ █ █ | |
⍝ ██ ██ ██ ██ | |
⍝ ███ ███ ███ ███ | |
⍝ ██ █ ██ █ ██ █ ██ █ | |
⍝ █████ █████ █████ █████ | |
⍝ ██ █ ██ █ ██ █ ██ █ | |
⍝ ███ ██ ███ ██ ███ ██ ███ ██ | |
⍝ ██ █ ███ ██ █ ███ ██ █ ███ ██ █ ███ | |
⍝ ███████ █ ███████ █ ███████ █ ███████ █ | |
⍝ ██ ███ ██ ███ ██ ███ ██ ███ | |
⍝ ███ ██ █ ███ ██ █ ███ ██ █ ███ ██ █ | |
⍝ ██ █ █████ ██ █ █████ ██ █ █████ ██ █ █████ | |
⍝ █████ ██ █ █████ ██ █ █████ ██ █ █████ ██ █ | |
⍝ ██ █ ███ ██ ██ █ ███ ██ ██ █ ███ ██ ██ █ ███ ██ | |
⍝ ███ ████ █ ██████ ████ █ ██████ ████ █ ██████ ████ █ ███ | |
⍝ █ ██ █████ █ ██ █████ █ ██ █████ █ ██ █████ | |
⍝ █████ ██ █ █████ ██ █ █████ ██ █ █████ ██ █ | |
⍝ ██ ████ ██ ██ ████ ██ ██ ████ ██ ██ ████ ██ | |
⍝ ██ ██ █ ███ ███ ██ █ ███ ███ ██ █ ███ ███ ██ █ ███ █ | |
⍝ █ ███ ████ ███ █ ███ ████ ███ █ ███ ████ ███ █ ███ ████ ███ | |
⍝ ████ ███ ███ █████ ███ ███ █████ ███ ███ █████ ███ ███ █ | |
⍝ ███ █ ██ ███ ███ █ ██ ███ ███ █ ██ ███ ███ █ ██ ███ | |
⍝ ██ ████████ █ ██ ████████ █ ██ ████████ █ ██ ████████ █ | |
⍝ █████ ███ █████ ███ █████ ███ █████ ███ | |
⍝ ██ █ ██ ███ █ ██ ███ █ ██ ███ █ ██ █ | |
⍝ █ ██ █████ █ ██ █████ █ ██ █████ █ ██ █████ | |
⍝ ██ ███ ██ ███ ███ ██ ███ ███ ██ ███ ███ ██ █ | |
⍝ ███ █ ███ ██ ███ █ ███ ██ ███ █ ███ ██ ███ █ ███ ██ | |
⍝ ██ ███ ██ █ █████ ███ ██ █ █████ ███ ██ █ █████ ███ ██ █ ███ | |
⍝ ███ ████████ ███ ████████ ███ ████████ ███ ████████ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment