Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 53s
Five infrastructure fixes to make the Hui formulation
{1 ⍵ ∨.∧ 3 4 = +/+/¯1 0 1 ∘.⊖ ¯1 0 1 ⌽¨ ⊂⍵} work:
1. apl-each-dyadic: unbox enclosed-array scalar before pairing;
preserve array results instead of disclosing
2. apl-outer: same dict-vs-number wrap detection
3. apl-reduce: dict-aware wrap in reducer; don't double-wrap
the final result in apl-scalar when it's already a dict
4. broadcast-dyadic: leading-axis extension for shape-(k) vs
shape-(k …) — `3 4 = M[5,5]` → shape (2 5 5)
5. :vec eval keeps non-scalar dicts intact (no flatten-to-first)
life.apl: drop leading ⊃ (Hui's ⊃ assumes inner-product produces
enclosed cell; our extension-style impl produces clean (5 5)).
Comment block in life.apl explains.
5 e2e tests: blinker oscillates period-2, 2×2 block stable,
empty grid stays empty, source file load via apl-run-file.
Full suite 578/578.
23 lines
1.1 KiB
APL
23 lines
1.1 KiB
APL
⍝ Conway's Game of Life — toroidal one-liner
|
||
⍝
|
||
⍝ Roger Hui formulation (without leading ⊃, since our inner-product
|
||
⍝ already produces a clean 2D board from a heterogeneous strand):
|
||
⍝ life ← {1 ⍵ ∨.∧ 3 4 = +/ +/ ¯1 0 1 ∘.⊖ ¯1 0 1 ⌽¨ ⊂⍵}
|
||
⍝
|
||
⍝ Read right-to-left:
|
||
⍝ ⊂⍵ : enclose the board (so it's a single scalar item)
|
||
⍝ ¯1 0 1 ⌽¨ ⊂⍵ : produce 3 horizontally-shifted copies
|
||
⍝ ¯1 0 1 ∘.⊖ … : outer-product with vertical shifts → 3×3 = 9 shifts
|
||
⍝ +/ +/ … : sum the 9 boards element-wise → neighbor-count + self
|
||
⍝ 3 4 = … : leading-axis-extended boolean — count is 3 (born) or 4 (survive)
|
||
⍝ 1 ⍵ ∨.∧ … : "alive next" iff (count=3) or (alive AND count=4)
|
||
⍝
|
||
⍝ Rules in plain language:
|
||
⍝ - dead cell + 3 live neighbors → born
|
||
⍝ - live cell + 2 or 3 live neighbors → survives
|
||
⍝ - all else → dies
|
||
⍝
|
||
⍝ Toroidal: edges wrap (rotate is cyclic).
|
||
|
||
life ← {1 ⍵ ∨.∧ 3 4 = +/ +/ ¯1 0 1 ∘.⊖ ¯1 0 1 ⌽¨ ⊂⍵}
|