picolisp

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/picolisp.git/
Log | Files | Refs | README | LICENSE

life.l (1335B)


      1 # 15mar10abu
      2 # (c) Software Lab. Alexander Burger
      3 
      4 (load "@lib/simul.l")
      5 
      6 (de life (DX DY . Init)
      7    (let Grid (grid DX DY)
      8       (for This Init
      9          (=: life T) )
     10       (loop
     11          (disp Grid NIL
     12             '((This) (if (: life) "X " "  ")) )
     13          (wait 1000)
     14          (for Col Grid
     15             (for This Col
     16                (let N  # Count neighbors
     17                   (cnt
     18                      '((Dir) (get (Dir This) 'life))
     19                      (quote
     20                         west east south north
     21                         ((X) (south (west X)))
     22                         ((X) (north (west X)))
     23                         ((X) (south (east X)))
     24                         ((X) (north (east X))) ) )
     25                   (=: next  # Next generation
     26                      (if (: life)
     27                         (>= 3 N 2)
     28                         (= N 3) ) ) ) ) )
     29          (for Col Grid  # Update
     30             (for This Col
     31                (=: life (: next)) ) ) ) ) )
     32 
     33 # Blinker (period 2)
     34 '(life 5 5  b3 c3 d3)
     35 
     36 # Glider
     37 '(life 9 9  a7 b7 b9 c7 c8)
     38 
     39 # Pulsar (period 3)
     40 (life 17 17
     41    b6 b12
     42    c6 c12
     43    d6 d7 d11 d12 
     44    f2 f3 f4 f7 f8 f10 f11 f14 f15 f16
     45    g4 g6 g8 g10 g12 g14
     46    h6 h7 h11 h12
     47    j6 j7 j11 j12
     48    k4 k6 k8 k10 k12 k14
     49    l2 l3 l4 l7 l8 l10 l11 l14 l15 l16
     50    n6 n7 n11 n12 
     51    o6 o12
     52    p6 p12 )
     53 
     54 # vi:et:ts=3:sw=3