Skip to content

Instantly share code, notes, and snippets.

View marick's full-sized avatar

Brian Marick marick

View GitHub Profile
;;; Based on an idea by Paul Blair and Michael Nicholaides @nicholaides
(def *horizontal-blinker* [ [0,1] [1,1], [2,1] ] )
(def *vertical-blinker* [ [1,2]
[1,1]
[1,0] ])
(example "of blinkers blinking"
(next-world *horizontal-blinker*) => *vertical-blinker*
(next-world *vertical-blinker*) => *horizontal-blinker*
@marick
marick / gist:434773
Created June 11, 2010 17:16
blinkers
(def *horizontal-blinker* [ [0,1] [1,1], [2,1] ] )
(def *vertical-blinker* [ [1,2]
[1,1]
[1,0] ])
(example "of blinkers blinking"
(next-world *horizontal-blinker*) => *vertical-blinker*
(next-world *vertical-blinker*) => *horizontal-blinker*
)
(pending border tick unborder)
(defn next-world [world]
(-> world
border tick unborder)
)
(defn next-world [world]
(unborder (tick (border world))))
(f ...cell...) => 10
(provided
(g ...cell...) => true
(h ...cell...) => 2)
(living? (successor ...cell...) => falsey
(provided
(living? ...cell...) => true
(living-neighbor-count ...cell...) => 0)
(successor ...cell...) =means=> (killed ...cell...) ;;; fix
(provided
(living? ...cell...) => true
(living-neighbor-count ...cell...) => 0)
cell = mock()
# expectations
cell.should_receive(:living?).at_least.once.and_return(true)
cell.should_receive(:living_neighbor_count).at_least_once.and_return(0)
cell.should_receive(:killed).at_least.once
# run test
cell.successor
(defn tick [bordered-world]
(against-background [world bordered-world]
(map successor bordered-world))
)
(know "rules that determine the life or death of a cell in the sucessor generation"
(successor ...cell...) =means=> (killed ...cell...)
(provided ; underpopulation
(living? ...cell...) => true
(living-neighbor-count ...cell...) =from=> [0, 1])
(or ; overpopulation
(living? ...cell...) => true
(living-neighbor-count ...cell...) =from=> [4 ,,, 8])
(or ; not enough cells to bring to life
(living? ...cell...) => false