Skip to content

Instantly share code, notes, and snippets.

@michaelsbradleyjr
Created June 7, 2012 18:48
Show Gist options
  • Save michaelsbradleyjr/2890736 to your computer and use it in GitHub Desktop.
Save michaelsbradleyjr/2890736 to your computer and use it in GitHub Desktop.
(defn neighbours
[[x y]]
(for [dx [-1 0 1] dy [-1 0 1] :when (not= 0 dx dy)]
[(+ dx x) (+ dy y)]))
(defn step
"Yields the next state of the world"
[cells]
(set (for [[loc n] (frequencies (mapcat neighbours cells))
:when (or (= n 3) (and (= n 2) (cells loc)))]
loc)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment