Skip to content

Instantly share code, notes, and snippets.

@nullkal
Created Sep 27, 2012
Embed
What would you like to do?
ライフゲーム
(define (rot_l l)
(append (cdr l) (list (car l))))
(define (rot_r l)
(reverse (rot_l (reverse l))))
(define (forward_generation g)
(map (lambda (m n)
(map (lambda (m n)
(if (= n 1)
(if (or (= m 2) (= m 3)) 1 0)
(if (= m 3) 1 0))) m n))
(map (lambda a (apply map + a))
(rot_l (map rot_l g))
(rot_l g)
(rot_l (map rot_r g))
(map rot_l g)
(map rot_r g)
(rot_r (map rot_l g))
(rot_r g)
(rot_r (map rot_r g)))
g))
(define (line_str str a)
(if (null? a) str
(let ((s (line_str str (cdr a))))
(if (= (car a) 1)
(string-append "*" s)
(string-append "." s)))))
(define (main g)
(map (lambda (a) (print (line_str "" a))) g)
(print "")
(sys-sleep 1)
(main (forward_generation g)))
(main '((0 0 1 0 0 0)
(1 0 1 0 0 0)
(0 1 1 0 0 0)
(0 0 0 0 0 0)
(0 0 0 0 0 0)
(0 0 0 0 0 0)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment