Permalink
Browse files

Original Christophe Grand's solution

  • Loading branch information...
1 parent b7d163d commit e31153f419b4f05e5df783236ac233607c4756dc Andrey Paramonov committed Dec 9, 2012
Showing with 5 additions and 6 deletions.
  1. +5 −6 src/dojo/life.clj
View
@@ -4,14 +4,13 @@
(ns dojo.life)
-; http://rosettacode.org/wiki/Conway's_Game_of_Life#Clojure
+; http://clj-me.cgrand.net/2011/08/19/conways-game-of-life/
(defn neighbours [[x y]]
- (for [dx [-1 0 1] dy [-1 0 1]
- :when (not (and (zero? dx) (zero? dy)))]
+ (for [dx [-1 0 1] dy (if (zero? dx) [-1 1] [-1 0 1])]
[(+ x dx) (+ y dy)]))
(defn next-step [cells]
- (set (for [[cell n] (frequencies (mapcat neighbours cells))
- :when (or (= n 3) (and (= n 2) (some #{cell} cells)))]
- cell)))
+ (set (for [[loc n] (frequencies (mapcat neighbours cells))
+ :when (or (= n 3) (and (= n 2) (cells loc)))]
+ loc)))

0 comments on commit e31153f

Please sign in to comment.