Skip to content

Instantly share code, notes, and snippets.

View marick's full-sized avatar

Brian Marick marick

View GitHub Profile
(defn cell-at [x y] [x y])
(defn x [cell] (first cell))
(defn y [cell] (second cell))
(defn have-coordinates [cells coordinates]
(= (set cells) (set coordinates)))
(defn neighbors [cell]
(let [product (cartesian-product [-1 0 1] [-1 0 1])
meaningful-values (remove #{ [0 0] } product)
shifter (fn [ [x-shift y-shift] ] (cell-at (+ (x cell) x-shift)
(pending border unborder
living? vivified killed)
{ [0 0] :alive, [0 1] :dead, [1 0] :dead, ... }
user=> (map (fn [x] x) { [0 0] :alive, [0 1] :dead, [1 0] :dead })
([[0 0] :alive] [[0 1] :dead] [[1 0] :dead])
(defn next-world [only-living-locations]
(using-cell-oracles-from only-living-locations
(-> only-living-locations
border tick unborder))
)
(know "that an oracle about living? can be created"
(using-cell-oracles-from [...location ...]
(living? ...location...)) => truthy
(using-cell-oracles-from [...location ...]
(living? ...somewhere-else...)) => falsey
)
(defn next-world [only-living-locations]
(using-cell-oracles-from only-living-locations
(remove dead-in-next-generation?
(add-border-to only-living-locations)))
)
(successor ...cell...) =means=> (killed ...cell...)
; became
(dead-in-next-generation? ...location...) => truthy
(defn dead-in-next-generation? [location]
(condp = (living-neighbor-count location)
3 false
2 (not (living? location))
true)
)
;;; The Life code is based on an idea by Paul Blair and Michael Nicholaides @nicholaides
(ns life
(:use [clojure.contrib.combinatorics :only (cartesian-product)])
(:use [clojure.set])
)
;;; Test stuff that's here because I haven't written the mocking package yet.