Paste: Life with ascii output
Author: | Björn Lindqvist |
Mode: | factor |
Date: | Mon, 3 Jun 2013 16:40:48 |
Plain Text |
USING:
assocs
io
kernel
lists lists.lazy
locals
math.statistics math.vectors
random
sequences
sets ;
IN: life
: neighbours
{ 1 0 -1 } dup cartesian-product concat [ { 0 0 } = not ] filter
[ v+ ] with map ;
:: live?
n 3 = n 2 = loc cells in? and or ;
:: life-step
cells [ neighbours ] map concat histogram
[ cells live? ] assoc-filter keys ;
: initial-cells
[ 2 [ 8 iota random ] replicate ] replicate ;
:: cells>grid
8 iota dup cartesian-product [ [ cells in? ] map ] map ;
: display-grid
[ [ "*" "." ? ] map "" join print ] each flush ;
: run-life
initial-cells [ life-step ] lfrom-by ltake
[ "---" print cells>grid display-grid ] leach ;
New Annotation