Skip to content

Instantly share code, notes, and snippets.

@rarous
Forked from kolman/gol.clj
Last active August 29, 2015 14:14
Show Gist options
  • Save rarous/4790c04c151201d9368e to your computer and use it in GitHub Desktop.
Save rarous/4790c04c151201d9368e to your computer and use it in GitHub Desktop.
(ns joyful-game.game-of-life)
(defn neighs [[x y]]
(for [dx [-1 0 1]
dy [-1 0 1]
:when (not (= 0 dy dx))]
[(+ x dx) (+ y dy)]))
(defn should-be-alive [nc is-alive]
(or (= nc 3)
(and (= nc 2) is-alive)))
(defn step [board]
(->> board
(mapcat neighs)
frequencies
(filter (fn [[cell frq]] (should-be-alive frq (board cell))))
(map first)
set))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment