On Mar 3, 2009, at 4:03 PM, Stephen C. Gilardi wrote:

(defn determine-new-state [x y]
 (let [count (reduce + (for [dx [-1 0 1] dy [-1 0 1]]
                         (if (cells [(+ x dx) (+ y dy)]) 1 0)))]
   (or (and (cells [x y]) (> count 2) (< count 5))
       (= count 3))))


I'm guessing someone can make the reduce even tighter.

Here's another shot at it:

(defn determine-new-state [x y]
  (let [nearby [-1 0 1]
        neighborhood (for [dx nearby dy nearby]
                       (cells [(+ x dx) (+ y dy)]))
        alive (count (filter identity neighborhood))]
    (if (cells [x y])
      (< 2 alive 5)
      (= alive 3))))

--Steve

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to