Thanks everyone for the suggestions. Very helpful.
On Mar 3, 2:03 pm, "Stephen C. Gilardi" <squee...@mac.com> wrote:
> 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
>
> smime.p7s
> 3KViewDownload
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---