Skip to content

Instantly share code, notes, and snippets.

@jramnani
Created January 25, 2016 20:51
Show Gist options
  • Save jramnani/51628308bde21c4c2bbc to your computer and use it in GitHub Desktop.
Save jramnani/51628308bde21c4c2bbc to your computer and use it in GitHub Desktop.
(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