Created
January 25, 2016 20:51
-
-
Save jramnani/51628308bde21c4c2bbc to your computer and use it in GitHub Desktop.
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 create-board | |
"Create a new board. Initializes all cells to be dead." | |
[num-columns num-rows] | |
(let [row (vec (repeat num-columns false)) | |
board (vec (repeat num-rows row))] | |
board)) | |
(defn generate-random-row | |
[num-columns] | |
(repeatedly num-columns #(if (>= 0.5 (rand 1)) true false))) | |
(defn create-random-board | |
"Create a new board. Randomly assigns cells to be alive or dead." | |
[num-columns num-rows] | |
(let [board (vec (repeatedly num-rows | |
#(generate-random-row num-columns)))] | |
board)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment