[racket] Challenge: Game of life in 140 chars
Hey there! Inspired by this article, I tried (quite
unsuccessfully) to make a very short, very contrived Game of
Life just for fun.
http://news.ycombinator.com/item?id=357938
How can we make this shorter?
;;;;;;;;; 8< ;;;;;;;;;;;;;; 8< ;;;;;;;;;;;;;;
#lang racket
(define glider
'((0 0 0 0 0 0 0 0 0 0)
(0 0 0 0 0 0 0 0 0 0)
(0 0 0 0 1 0 0 0 0 0)
(0 0 0 0 0 1 0 0 0 0)
(0 0 0 1 1 1 0 0 0 0)
(0 0 0 0 0 0 0 0 0 0)
(0 0 0 0 0 0 0 0 0 0)
(0 0 0 0 0 0 0 0 0 0)
(0 0 0 0 0 0 0 0 0 0)
(0 0 0 0 0 0 0 0 0 0)))
(define (life board s)
(for/list ([r s])
(for/list ([c s])
(let* ([v (λ(r c) (list-ref (list-ref board (modulo r s)) (modulo c s)))]
[n (count positive
(map (λ(y x)(v (- r y) (- c x)))
'(-1 -1 -1 0 0 1 1 1)
'(-1 0 1 -1 1 -1 0 1)))])
(if (or (and (positive (v r c))
(= 2 n))
(= 3 n))
1 0)))))
--
Be well,
_mike