This file contains 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
;;; 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* |
This file contains 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
(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* | |
) |
This file contains 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 tick unborder) | |
(defn next-world [world] | |
(-> world | |
border tick unborder) | |
) |
This file contains 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 [world] | |
(unborder (tick (border world)))) |
This file contains 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
(f ...cell...) => 10 | |
(provided | |
(g ...cell...) => true | |
(h ...cell...) => 2) |
This file contains 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
(living? (successor ...cell...) => falsey | |
(provided | |
(living? ...cell...) => true | |
(living-neighbor-count ...cell...) => 0) |
This file contains 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...) ;;; fix | |
(provided | |
(living? ...cell...) => true | |
(living-neighbor-count ...cell...) => 0) |
This file contains 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
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 |
This file contains 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 tick [bordered-world] | |
(against-background [world bordered-world] | |
(map successor bordered-world)) | |
) |
This file contains 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 "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 |