-
-
Save mikera/1130280 to your computer and use it in GitHub Desktop.
Revisions
-
There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ ;; enodyt's solution to Game of Life ;; https://4clojure.com/problem/94 (fn [board] (let [dx (count (first board)) dy (count board) neighbours (fn [pos board] (let [xs [[-1 -1] [0 -1] [1 -1] [-1 0] [1 0] [-1 1] [0 1] [1 1]]] (count (filter #(= % \#) (map #(get-in board (map + pos %)) xs)))))] (map #(apply str %) (partition dx (for [x (range dx) y (range dy)] (let [n (neighbours [x y] board) live? (= \# (get-in board [x y]))] (cond (and live? (< n 2)) \space (and live? (or (= n 2) (= n 3))) \# (and live? (> n 3)) \space (and (not live?) (= n 3)) \# :else \space)))))))