Skip to content

Instantly share code, notes, and snippets.

@marick
Created September 19, 2011 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save marick/1226430 to your computer and use it in GitHub Desktop.
Save marick/1226430 to your computer and use it in GitHub Desktop.
(ns scratch.core
(:use midje.sweet
[clojure.set :only [union intersection]]
:reload))
(unfinished newborns)
(defn survivable? [cell living-cells])
;; (fact "A cell is survivable if 2 or 3 of its neighbors are alive"
;; (survivable? ..cell.. ..living-cells..) => truthy
;; (provided
;; (intersection (neighborhood ..cell..) ..living-cells..) => ...living-cells-in-that-neighborhood..)
(defn survivors [living-cells]
(map (fn [cell] (survivable? cell living-cells))
living-cells))
(defn tick [living-cells]
(union (set (newborns living-cells))
(set (survivors living-cells))))
;.;. For every disciplined effort, there is a multiple reward. -- Rohn
(fact "the tick produces newborn cells and surviving cells"
(tick ..living-cells..) => (just [..newborn.. ..survivor..]
:in-any-order)
(provided
(newborns ..living-cells..) => [..newborn.. ..survivor..]
(survivors ..living-cells..) => [..survivor..]))
(defn generations [living-cells]
(rest (iterate tick living-cells)))
(fact "generations are produced by the tick function"
(first (generations ..living-cells..)) => ..generation-1..
(provided
(tick ..living-cells..) => ..generation-1..)
(second (generations ..living-cells..)) => ..generation-2..
(provided
(tick (tick ..living-cells..)) => ..generation-2..))
(future-fact "blinkers blink")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment