Created
September 27, 2012 12:26
-
-
Save nullkal/3793727 to your computer and use it in GitHub Desktop.
ライフゲーム
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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