Skip to content

Instantly share code, notes, and snippets.

@kitofr
Created September 15, 2011 18:59
Show Gist options
  • Save kitofr/1220144 to your computer and use it in GitHub Desktop.
Save kitofr/1220144 to your computer and use it in GitHub Desktop.
game of life?
(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