Paste: Game of Life, Clojure>Factor

Author: Kabelo Moiloa
Mode: factor
Date: Sun, 12 May 2013 15:08:20
Plain Text |
:: frequencies ( seq -- freq-table )
  H{ } clone :> table
  seq [ table inc-at ] each
  table ;

: neighbours ( loc -- neighbours )
  { 1 0 -1 } dup cartesian-product concat [ { 0 0 } = not ] filter
  [ v+ ] with map ;


:: step ( cells -- cells' )
   cells [ neighbours ] map concat frequencies
   [ [ nip 3 = ] [ nip 2 = ] [ drop cells in? ] 2tri and or ]
   assoc-filter keys ;

New Annotation

Summary:
Author:
Mode:
Body: