Created
September 15, 2011 18:59
-
-
Save kitofr/1220144 to your computer and use it in GitHub Desktop.
game of life?
This file contains 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
(def width 50) | |
(def height 50) | |
(defn populated? [pos] | |
true) | |
(defn unpopulated? [pos] | |
false) | |
(defn neighbors [pos] | |
[]) | |
(defn neighbor-count [pos] | |
(count neighbors pos)) | |
(defn loney? [pos] | |
(< (neighbor-count pos) 2)) | |
(defn overpopulated? [pos] | |
(>= (neighbor-count pos) 4)) | |
(defn survivor? [pos] | |
(or (= (neighbor-count pos) 2) | |
(= (neighbor-count pos) 3))) | |
(defn fertile? [pos] | |
(= (neighbor-count pos) 3)) | |
(defn draw-world [] | |
(doseq [y (range height)] | |
(print "|") | |
(doseq [x (range width)] | |
(print (if (populated? (to-pos x y)) | |
"*" | |
" ")) | |
(println "|")))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment