This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(pending border unborder | |
living? vivified killed) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ [0 0] :alive, [0 1] :dead, [1 0] :dead, ... } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user=> (map (fn [x] x) { [0 0] :alive, [0 1] :dead, [1 0] :dead }) | |
([[0 0] :alive] [[0 1] :dead] [[1 0] :dead]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn next-world [only-living-locations] | |
(using-cell-oracles-from only-living-locations | |
(-> only-living-locations | |
border tick unborder)) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn next-world [only-living-locations] | |
(using-cell-oracles-from only-living-locations | |
(remove dead-in-next-generation? | |
(add-border-to only-living-locations))) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(successor ...cell...) =means=> (killed ...cell...) | |
; became | |
(dead-in-next-generation? ...location...) => truthy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn dead-in-next-generation? [location] | |
(condp = (living-neighbor-count location) | |
3 false | |
2 (not (living? location)) | |
true) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 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. |