Re: Help Improving Game Of Life in clojure

2009-04-19 Thread Timothy Pratley
Hi Michael, Larry recently posted something similar http://groups.google.com/group/clojure/browse_thread/thread/773e628953b40d9f Which generated also quite a lot of discussion which you might also be interested in. (def matrix #{[-1 -1] [-1 0] [-1 1] [0 -1] [0 0] [0 1] [1 -1] [1 0] [1 1]})

Re: Help Improving Game Of Life in clojure

2009-04-19 Thread Michael Hunger
Thanks for the great feedback. Michael Am 19.04.2009 11:33 Uhr, schrieb Timothy Pratley: Hi Michael, Larry recently posted something similar http://groups.google.com/group/clojure/browse_thread/thread/773e628953b40d9f Which generated also quite a lot of discussion which you might also be

Help Improving Game Of Life in clojure

2009-04-18 Thread Michael Hunger
As I'm currently trying to learn clojure I wrote a game of life to get a feeling for the concepts. It would be great if some of you could point out areas for improvement or unused idioms or patterns. Thanks alot Michael here is the code: (ns gol) (comment a board only contains

Re: Parallel Game of Life

2009-03-20 Thread Scott Fraser
to experiment with different automata such as gliders. Larry Sherrill On Mar 16, 9:33 am, Kyle R. Burton kyle.bur...@gmail.com wrote: On Mon, Mar 16, 2009 at 12:31 AM, Scott Fraser scott.e.fra...@gmail.com wrote: I have taken Larry's Game of Life example that he originally posted here

Re: Parallel Game of Life

2009-03-16 Thread bOR_
Nice! A few more days of work and I've time to play with these kind of things again. Here are some comments, based on your description. As game of life is a cellular automata, you do not need any blocking at all, so you could use agents, rather than refs. It does become an asynchronous CA

Re: Parallel Game of Life

2009-03-16 Thread Larry Sherrill
days of work and I've time to play with these kind of things again. Here are some comments, based on your description. As game of life is a cellular automata, you do not need any blocking at all, so you could use agents, rather than refs. It does become an asynchronous CA then, but that fits

Re: Parallel Game of Life

2009-03-16 Thread Laurent PETIT
Hello, 2009/3/16 bOR_ boris.sch...@gmail.com Nice! A few more days of work and I've time to play with these kind of things again. Here are some comments, based on your description. As game of life is a cellular automata, you do not need any blocking at all, so you could use agents, rather

Re: Game of Life

2009-03-16 Thread Larry Sherrill
Very cool. Thanks for the tip. I didn't know a type hint would make that much difference. Another possible speedup would be to use send/actor to take advantage of multiprocessor machines. Would be curious if the overhead would pay for itself in this situation. Thanks, Larry On Mar 14, 8:03 pm,

Re: Parallel Game of Life

2009-03-16 Thread Kyle R. Burton
On Mon, Mar 16, 2009 at 12:31 AM, Scott Fraser scott.e.fra...@gmail.com wrote: I have taken Larry's Game of Life example that he originally posted here: http://groups.google.com/group/clojure/msg/fdfc88f1ba95bdee ...and updated it to use all the CPU's your JVM has access to... Scott, Your

Re: Parallel Game of Life

2009-03-16 Thread Larry Sherrill
, Kyle R. Burton kyle.bur...@gmail.com wrote: On Mon, Mar 16, 2009 at 12:31 AM, Scott Fraser scott.e.fra...@gmail.com wrote: I have taken Larry's Game of Life example that he originally posted here: http://groups.google.com/group/clojure/msg/fdfc88f1ba95bdee ...and updated it to use all

Re: Parallel Game of Life

2009-03-16 Thread bOR_
I'm not very used to concurrent programming, so I have a few questions you may find naïve, but well, let's just pretend they're interesting  ... : Learning here as well :). It seems to me that the game of life works in increments of its world. So I don't see at first what can be gained

Re: Parallel Game of Life

2009-03-16 Thread Scott Fraser
to experiment with different automata such as gliders. Larry Sherrill On Mar 16, 9:33 am, Kyle R. Burton kyle.bur...@gmail.com wrote: On Mon, Mar 16, 2009 at 12:31 AM, Scott Fraser scott.e.fra...@gmail.com wrote: I have taken Larry's Game of Life example that he originally posted here

Re: Game of Life

2009-03-15 Thread Scott Fraser
Hi Larry I have a performance tweak, that gives about an order of magnitude speedup to paint-cells when running this with a large grid and no or little (Thread/sleep life-delay) in toggle-thread. That is how I am running it now - 128 x 192 cells with no delay! It is also noticeably faster on the

Parallel Game of Life

2009-03-15 Thread Scott Fraser
I have taken Larry's Game of Life example that he originally posted here: http://groups.google.com/group/clojure/msg/fdfc88f1ba95bdee ...and updated it to use all the CPU's your JVM has access to. My first attempts ran into the classic map - pmap slowdown. My next attempt had too much dosync

Re: Game of Life

2009-03-04 Thread Larry Sherrill
I've incorporated everyone's suggestions and thought I would post the resulting smaller code. I refactored init-cells away and just pass in an init or new function to calc-state to reuse the for loop. I made determine-next-state a little more verbose than technically necessary to make conway's

Re: Game of Life

2009-03-04 Thread Raffael Cavallaro
In my experience, life is a bit more interesting if the field wraps and it is square. Here are some mods to your most recent version that does this. I've also parameterized the field size, the delay, and the initial probability of a cell being occupied. Thanks for sharing this - it's fun.

Game of Life

2009-03-03 Thread lps540
I've written a small example of Conway's Game of Life using Clojure and Swing. Comments/critiques are welcome. http://lpsherrill.blogspot.com/2009/02/conways-game-of-life.html Thanks, Larry --~--~-~--~~~---~--~~ You received this message because you

Re: Game of Life

2009-03-03 Thread Phil Hagelberg
lps540 lps...@gmail.com writes: I've written a small example of Conway's Game of Life using Clojure and Swing. Comments/critiques are welcome. Interesting program! (for [x (range 32) y (range 48)] (ref-set cells (assoc (deref cells) [x y] (= 0 (rand-int

Re: Game of Life

2009-03-03 Thread Larry Sherrill
a Java idiom. I'll read up on binding. Thank again! Larry On Mar 3, 1:30 pm, Phil Hagelberg p...@hagelb.org wrote: lps540 lps...@gmail.com writes: I've written a small example of Conway's Game of Life using Clojure and Swing. Comments/critiques are welcome. Interesting program!     (for [x

Re: Game of Life

2009-03-03 Thread Mark Volkmann
On Tue, Mar 3, 2009 at 2:03 PM, lps540 lps...@gmail.com wrote: I've written a small example of Conway's Game of Life using Clojure and Swing. Comments/critiques are welcome. http://lpsherrill.blogspot.com/2009/02/conways-game-of-life.html The paint-cells function can be shorted by using

Re: Game of Life

2009-03-03 Thread Mark Volkmann
On Tue, Mar 3, 2009 at 2:03 PM, lps540 lps...@gmail.com wrote: I've written a small example of Conway's Game of Life using Clojure and Swing. Comments/critiques are welcome. Instead of all the uses of (- x 1), (- y 1), (+ x 1) and (+ y 1), I think it's more idiomatic to use (dec x), (dec y

Re: Game of Life

2009-03-03 Thread Stephen C. Gilardi
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

Re: Game of Life

2009-03-03 Thread Larry Sherrill
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

Re: Game of Life

2009-03-03 Thread Laurent PETIT
Hello Larry, is there a reason why the code of this port of Game of Life does not seem to be under an open source license (e.g. EPL, etc.) ? I was interested in playing with your code, but I'm a bit reluctant when I see an all rights reserved in the top of the file ... It seems to me like your

Re: Game of Life

2009-03-03 Thread Stephen C. Gilardi
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

Re: Game of Life

2009-03-03 Thread Timothy Pratley
Just because there is always another way :P (defn determine-new-state [x y] (let [alive (count (for [dx [-1 0 1] dy [-1 0 1] :when (cells [(+ x dx) (+ y dy)])] :alive))] (if (cells [x y]) ( 2 alive 5) (= alive 3

Re: Game of Life

2009-03-03 Thread Larry Sherrill
laurent.pe...@gmail.com wrote: Hello Larry, is there a reason why the code of this port of Game of Life does not seem to be under an open source license (e.g. EPL, etc.) ? I was interested in playing with your code, but I'm a bit reluctant when I see an all rights reserved in the top

Re: Game of Life

2009-03-03 Thread Stephen C. Gilardi
On Mar 3, 2009, at 11:01 PM, Timothy Pratley wrote: Just because there is always another way :P (defn determine-new-state [x y] (let [alive (count (for [dx [-1 0 1] dy [-1 0 1] :when (cells [(+ x dx) (+ y dy)])] :alive))] (if (cells [x y])