⍝ John Conway's "Game of Life":

⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝ 2-manifold operators:

    adj←{                               ⍝ ┌─→─┐   ┌─→─┐ edges adjacent
        ⍺⍺ ⍵                            ⍝       →
    }                                   ⍝ └─→─┘   └─→─┘

    cut←{                               ⍝ ┌─→─┐   ┌───┐ edges blocked
        1↓⍺⍺ 0⍪⍵                        ⍝       →
    }                                   ⍝ └─→─┘   └───┘

    rev←{                               ⍝ ┌─→─┐   ┌─←─┐ edges reversed
        2↓¯1⊖⍺⍺ ¯1⊖⍵⍪⊖⌽2↑¯1⊖⍵           ⍝       →
    }                                   ⍝ └─→─┘   └─→─┘

    T←{⍉⍺⍺⍉⍵}                           ⍝ under transpose                 ⍢⍉<V>

⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝

    glider ← 5 5↑ 3 3⍴0 0 1, 1 0 1, 0 1 1   ⍝ initial population.

    try ← {{'·⍟'[⎕io+⍵]}¨⍺⍺ traj ⍵}

    life cut T cut try glider           ⍝ life on a finite plane
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│··⍟··│·⍟···│··⍟··│·····│·····│·····│·····│·····│·····│·····│·····│·····│
│⍟·⍟··│··⍟⍟·│···⍟·│·⍟·⍟·│···⍟·│··⍟··│···⍟·│·····│·····│·····│·····│·····│
│·⍟⍟··│·⍟⍟··│·⍟⍟⍟·│··⍟⍟·│·⍟·⍟·│···⍟⍟│····⍟│··⍟·⍟│····⍟│···⍟·│·····│·····│
│·····│·····│·····│··⍟··│··⍟⍟·│··⍟⍟·│··⍟⍟⍟│···⍟⍟│··⍟·⍟│····⍟│····⍟│···⍟⍟│
│·····│·····│·····│·····│·····│·····│·····│···⍟·│···⍟⍟│···⍟⍟│···⍟⍟│···⍟⍟│
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘

    life adj T cut try 10 5↑glider      ⍝ life on a cylinder
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│··⍟··│·⍟···│··⍟··│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│
│⍟·⍟··│··⍟⍟·│···⍟·│·⍟·⍟·│···⍟·│··⍟··│···⍟·│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│
│·⍟⍟··│·⍟⍟··│·⍟⍟⍟·│··⍟⍟·│·⍟·⍟·│···⍟⍟│····⍟│··⍟·⍟│····⍟│···⍟·│····⍟│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│
│·····│·····│·····│··⍟··│··⍟⍟·│··⍟⍟·│··⍟⍟⍟│···⍟⍟│··⍟·⍟│⍟···⍟│⍟····│⍟··⍟·│⍟····│····⍟│⍟····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│
│·····│·····│·····│·····│·····│·····│·····│···⍟·│···⍟⍟│···⍟⍟│⍟··⍟⍟│⍟···⍟│⍟··⍟·│⍟⍟···│·⍟···│·⍟··⍟│·⍟···│⍟····│·⍟···│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│
│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│····⍟│⍟···⍟│⍟···⍟│⍟⍟··⍟│⍟⍟···│·⍟··⍟│·⍟⍟··│··⍟··│⍟·⍟··│··⍟··│·⍟···│··⍟··│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│
│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│⍟····│⍟⍟···│⍟⍟···│⍟⍟⍟··│·⍟⍟··│⍟·⍟··│··⍟⍟·│···⍟·│·⍟·⍟·│···⍟·│··⍟··│···⍟·│·····│·····│·····│·····│·····│·····│·····│
│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·⍟···│·⍟⍟··│·⍟⍟··│·⍟⍟⍟·│··⍟⍟·│·⍟·⍟·│···⍟⍟│····⍟│··⍟·⍟│····⍟│···⍟·│····⍟│·····│·····│·····│
│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│··⍟··│··⍟⍟·│··⍟⍟·│··⍟⍟⍟│···⍟⍟│··⍟·⍟│⍟···⍟│⍟····│⍟··⍟·│⍟····│⍟···⍟│
│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│···⍟·│···⍟⍟│···⍟⍟│⍟··⍟⍟│⍟···⍟│⍟···⍟│⍟···⍟│
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘

    life adj T adj try glider           ⍝ life on a torus
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│··⍟··│·⍟···│··⍟··│·····│·····│·····│·····│·····│·····│·····│·····│····⍟│⍟···⍟│⍟···⍟│⍟⍟··⍟│⍟⍟···│·⍟··⍟│·⍟⍟··│··⍟··│⍟·⍟··│
│⍟·⍟··│··⍟⍟·│···⍟·│·⍟·⍟·│···⍟·│··⍟··│···⍟·│·····│·····│·····│·····│·····│·····│·····│·····│⍟····│⍟⍟···│⍟⍟···│⍟⍟⍟··│·⍟⍟··│
│·⍟⍟··│·⍟⍟··│·⍟⍟⍟·│··⍟⍟·│·⍟·⍟·│···⍟⍟│····⍟│··⍟·⍟│····⍟│···⍟·│····⍟│·····│·····│·····│·····│·····│·····│·····│·····│·⍟···│
│·····│·····│·····│··⍟··│··⍟⍟·│··⍟⍟·│··⍟⍟⍟│···⍟⍟│··⍟·⍟│⍟···⍟│⍟····│⍟··⍟·│⍟····│····⍟│⍟····│·····│·····│·····│·····│·····│
│·····│·····│·····│·····│·····│·····│·····│···⍟·│···⍟⍟│···⍟⍟│⍟··⍟⍟│⍟···⍟│⍟··⍟·│⍟⍟···│·⍟···│·⍟··⍟│·⍟···│⍟····│·⍟···│·····│
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘

    life cut T rev try 5 10↑glider      ⍝ life on a möbius strip
┌──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┐
│··⍟·······│·⍟········│··⍟·······│··········│··········│··········│··········│··········│··········│··········│··········│·····⍟····│····⍟⍟····│····⍟⍟····│···⍟⍟⍟····│···⍟⍟·····│···⍟·⍟····│··⍟⍟······│··⍟·······│··⍟·⍟·····│··⍟·······│···⍟······│··⍟·······│··········│··········│··········│··········│··········│··········│··········│··········│··········│
│⍟·⍟·······│··⍟⍟······│···⍟······│·⍟·⍟······│···⍟······│··⍟·······│···⍟······│··········│··········│··········│··········│··········│··········│··········│··········│····⍟·····│···⍟⍟·····│···⍟⍟·····│··⍟⍟⍟·····│··⍟⍟······│··⍟·⍟·····│·⍟⍟·······│·⍟········│·⍟·⍟······│·⍟········│··⍟·······│·⍟········│··········│··········│··········│··········│··········│
│·⍟⍟·······│·⍟⍟·······│·⍟⍟⍟······│··⍟⍟······│·⍟·⍟······│···⍟⍟·····│····⍟·····│··⍟·⍟·····│····⍟·····│···⍟······│····⍟·····│··········│··········│··········│··········│··········│··········│··········│··········│···⍟······│··⍟⍟······│··⍟⍟······│·⍟⍟⍟······│·⍟⍟·······│·⍟·⍟······│⍟⍟········│⍟·········│⍟·⍟·······│⍟·········│·⍟········│··········│··········│
│··········│··········│··········│··⍟·······│··⍟⍟······│··⍟⍟······│··⍟⍟⍟·····│···⍟⍟·····│··⍟·⍟·····│····⍟⍟····│·····⍟····│···⍟·⍟····│·····⍟····│····⍟·····│·····⍟····│··········│··········│··········│··········│··········│··········│··········│··········│··⍟·······│·⍟⍟·······│·⍟⍟·······│⍟⍟⍟·······│⍟⍟········│⍟·⍟·······│⍟·········│⍟·········│⍟⍟········│
│··········│··········│··········│··········│··········│··········│··········│···⍟······│···⍟⍟·····│···⍟⍟·····│···⍟⍟⍟····│····⍟⍟····│···⍟·⍟····│·····⍟⍟···│······⍟···│····⍟·⍟···│······⍟···│·····⍟····│······⍟···│··········│··········│··········│··········│··········│··········│··········│··········│·⍟········│⍟⍟········│⍟⍟········│⍟⍟········│⍟⍟········│
└──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┘

    life adj T rev try glider           ⍝ life on a klein bottle
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│··⍟··│·⍟···│··⍟··│·····│·····│·····│·····│·····│·····│·····│·····│⍟····│⍟···⍟│⍟···⍟│⍟··⍟⍟│···⍟⍟│⍟··⍟·│··⍟⍟·│··⍟··│··⍟·⍟│··⍟··│···⍟·│··⍟··│·····│·····│·····│·····│·····│·····│·····│·····│····⍟│⍟···⍟│⍟···⍟│⍟⍟··⍟│⍟⍟···│·⍟··⍟│·⍟⍟··│··⍟··│⍟·⍟··│
│⍟·⍟··│··⍟⍟·│···⍟·│·⍟·⍟·│···⍟·│··⍟··│···⍟·│·····│·····│·····│·····│·····│·····│·····│·····│····⍟│···⍟⍟│···⍟⍟│··⍟⍟⍟│··⍟⍟·│··⍟·⍟│·⍟⍟··│·⍟···│·⍟·⍟·│·⍟···│··⍟··│·⍟···│·····│·····│·····│·····│·····│·····│·····│·····│⍟····│⍟⍟···│⍟⍟···│⍟⍟⍟··│·⍟⍟··│
│·⍟⍟··│·⍟⍟··│·⍟⍟⍟·│··⍟⍟·│·⍟·⍟·│···⍟⍟│····⍟│··⍟·⍟│····⍟│···⍟·│····⍟│·····│·····│·····│·····│·····│·····│·····│·····│···⍟·│··⍟⍟·│··⍟⍟·│·⍟⍟⍟·│·⍟⍟··│·⍟·⍟·│⍟⍟···│⍟····│⍟·⍟··│⍟····│·⍟···│⍟····│·····│·····│·····│·····│·····│·····│·····│·····│·⍟···│
│·····│·····│·····│··⍟··│··⍟⍟·│··⍟⍟·│··⍟⍟⍟│···⍟⍟│··⍟·⍟│⍟···⍟│⍟····│⍟··⍟·│⍟····│····⍟│⍟····│·····│·····│·····│·····│·····│·····│·····│·····│··⍟··│·⍟⍟··│·⍟⍟··│⍟⍟⍟··│⍟⍟···│⍟·⍟··│⍟···⍟│····⍟│·⍟··⍟│····⍟│⍟····│····⍟│·····│·····│·····│·····│·····│
│·····│·····│·····│·····│·····│·····│·····│···⍟·│···⍟⍟│···⍟⍟│⍟··⍟⍟│⍟···⍟│⍟··⍟·│⍟⍟···│·⍟···│·⍟··⍟│·⍟···│⍟····│·⍟···│·····│·····│·····│·····│·····│·····│·····│·····│·⍟···│⍟⍟···│⍟⍟···│⍟⍟··⍟│⍟···⍟│·⍟··⍟│···⍟⍟│···⍟·│⍟··⍟·│···⍟·│····⍟│···⍟·│·····│
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘

    life rev T rev try 11 5↑glider      ⍝ life on the real projective plane (RP2)
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│··⍟··│·⍟···│··⍟··│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│····⍟│····⍟│····⍟│·····│·····│
│⍟·⍟··│··⍟⍟·│···⍟·│·⍟·⍟·│···⍟·│··⍟··│···⍟·│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│···⍟·│···⍟⍟│···⍟⍟│···⍟⍟│····⍟│···⍟·│·····│·····│·····│
│·⍟⍟··│·⍟⍟··│·⍟⍟⍟·│··⍟⍟·│·⍟·⍟·│···⍟⍟│····⍟│··⍟·⍟│····⍟│···⍟·│····⍟│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│··⍟··│··⍟⍟·│··⍟⍟·│··⍟⍟⍟│···⍟⍟│··⍟·⍟│····⍟│·····│···⍟·│·····│····⍟│·····│·····│
│·····│·····│·····│··⍟··│··⍟⍟·│··⍟⍟·│··⍟⍟⍟│···⍟⍟│··⍟·⍟│····⍟│·····│···⍟·│·····│····⍟│·····│·····│·····│·····│·····│·⍟···│·⍟⍟··│·⍟⍟··│·⍟⍟⍟·│··⍟⍟·│·⍟·⍟·│···⍟⍟│····⍟│··⍟·⍟│····⍟│···⍟·│····⍟│·····│·····│·····│·····│·····│
│·····│·····│·····│·····│·····│·····│·····│···⍟·│···⍟⍟│···⍟⍟│···⍟⍟│····⍟│···⍟·│·····│·····│⍟···⍟│⍟⍟···│⍟⍟···│⍟⍟⍟··│·⍟⍟··│⍟·⍟··│··⍟⍟·│···⍟·│·⍟·⍟·│···⍟·│··⍟··│···⍟·│·····│·····│·····│·····│·····│·····│·····│·····│·····│
│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│····⍟│⍟···⍟│⍟···⍟│⍟⍟··⍟│⍟⍟···│·⍟··⍟│·⍟⍟··│··⍟··│⍟·⍟··│··⍟··│·⍟···│··⍟··│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│
│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│⍟····│⍟····│⍟····│⍟⍟···│·⍟···│·⍟···│·⍟···│⍟····│·⍟···│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│
│·····│·····│·····│·····│·····│·····│·····│·····│·····│⍟····│⍟····│⍟····│⍟····│·····│⍟····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│
│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│⍟····│⍟····│⍟····│⍟····│·····│·····│·····│
│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│⍟····│⍟····│⍟····│⍟····│⍟····│·····│
│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│·····│⍟····│·⍟···│·····│
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘

Back to: code

Back to: Workspaces