Advertisement
Guest User

Untitled

a guest
Jul 10th, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 0.60 KB | None | 0 0
  1. ; unbounded linear with n cells conways game of life
  2.  
  3. (l "core")
  4.  
  5. (= moore-neighborhood (rem [iso _ '(0 0)] (flat1:mapn list -1 1 -1 1)))
  6.  
  7. (def translate (cells dir)
  8.   (set-map [map + _cell dir] cells))
  9.  
  10. (def neighborhood (cells)
  11.   (table-map-values len
  12.     (union-tables:map [translate cells _] moore-neighborhood)))
  13.  
  14. (def next-gen (cells)
  15.   (table-map-to-values
  16.     (fn (key count) (case count 3 t 2 cells.key))
  17.     neighborhood.cells))
  18.  
  19. (def conway (cells gens)
  20.   (zap to-set cells)
  21.   (repeat gens
  22.     prn:ppr:keys.cells
  23.     (zap next-gen cells)))
  24.  
  25. (= blinker '((1 2) (2 2) (3 2)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement