On Mar 3, 2009, at 3:03 PM, lps540 wrote:

I've written a small example of Conway's Game of Life using Clojure
and Swing. Comments/critiques are welcome.

Very nice example!

Here's a more compact determine-new-state:

(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.

I considered using :when (not (and (zero? dx) (zero? dy))) in the for expression, but it seemed simpler to account for the extra count when (cells [x y]) is true in the new state expression down below.

--Steve

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

Reply via email to