-
-
Save rarous/4790c04c151201d9368e to your computer and use it in GitHub Desktop.
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 characters
(ns joyful-game.game-of-life) | |
(defn neighs [[x y]] | |
(for [dx [-1 0 1] | |
dy [-1 0 1] | |
:when (not (= 0 dy dx))] | |
[(+ x dx) (+ y dy)])) | |
(defn should-be-alive [nc is-alive] | |
(or (= nc 3) | |
(and (= nc 2) is-alive))) | |
(defn step [board] | |
(->> board | |
(mapcat neighs) | |
frequencies | |
(filter (fn [[cell frq]] (should-be-alive frq (board cell)))) | |
(map first) | |
set)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment