Re: help needed to use reducers and monoid

2012-08-20 Thread Jim - FooBar();
On 20/08/12 12:34, Jim - FooBar(); wrote: On 20/08/12 10:12, nicolas.o...@gmail.com wrote: (defn generate [board next-boards] ;; next-boards return a seq of MoveAndBoard (BoardAndChildren. board (r/map (fn [m] (MoveAndTree.

Re: help needed to use reducers and monoid

2012-08-20 Thread Jim - FooBar();
On 20/08/12 10:12, nicolas.o...@gmail.com wrote: (defn generate [board next-boards] ;; next-boards return a seq of MoveAndBoard (BoardAndChildren. board (r/map (fn [m] (MoveAndTree. (:move m)

Re: help needed to use reducers and monoid

2012-08-20 Thread nicolas.o...@gmail.com
(defn generate [board next-boards] ;; next-boards return a seq of MoveAndBoard (BoardAndChildren. board (r/map (fn [m] (MoveAndTree. (:move m) (generate (:board m) next

Re: help needed to use reducers and monoid

2012-08-19 Thread Jim - FooBar();
Hi Nicolas, as you can see I couldn't sleep without trying out your snippet! :-) Unfortunately, your code gives me a: NullPointerException clojure.lang.Numbers.ops (Numbers.java:942) clojure.lang.Numbers.gt (Numbers.java:227) clojure.core/max-key (core.clj:4434) clojure.core/max-

Re: help needed to use reducers and monoid

2012-08-19 Thread nicolas.o...@gmail.com
A correction for the wrong part: (defn my-max ([x y] (if (nil? x) y (if (nil? y) x (max x y ([] nil)) (defn tree-value ^double [tree evaluate ^long depth] (let [children (:children tree)] (if (or (zero? depth)) (evaluate (:board t

Re: help needed to use reducers and monoid

2012-08-19 Thread nicolas.o...@gmail.com
> > thanks a lot Nicolas...I'll definitely play around with your code tomorrow > morning...if you say you can go up to level 5 in 11 sec this is really good > performance -I can't wait to explore the code...I'll let you know of any > comments of mine soon! > > Of course, don't trust this code. I ha

Re: help needed to use reducers and monoid

2012-08-19 Thread Jim - FooBar();
On 19/08/12 21:09, nicolas.o...@gmail.com wrote: By the way, I just found an obvious bug in that code, but that should be easy to correct. (if (= res Double/NEGATIVE_INFINITY) (evaluate (:board tree)) res This is obviously wrong. thanks a lot Nicolas...I'll definitely pla

Re: help needed to use reducers and monoid

2012-08-19 Thread nicolas.o...@gmail.com
By the way, I just found an obvious bug in that code, but that should be easy to correct. (if (= res Double/NEGATIVE_INFINITY) (evaluate (:board tree)) res This is obviously wrong. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To

Re: help needed to use reducers and monoid

2012-08-19 Thread nicolas.o...@gmail.com
Hi Jim, I tried a bit. The performance of this is not perfect but seems not horrible. It can do a level 5 exploration in 11 sec on my computer, with a branching factor of 30. (Of course, there is very little computation for the next move.) The generation is now lazy, but the depth is used in the e

Re: help needed to use reducers and monoid

2012-08-19 Thread Jim - FooBar();
HI nicolas, first of all thanks for your time...I do appreciate it...Ok let's see, On 19/08/12 13:01, nicolas.o...@gmail.com wrote: You might use the fact that -Infinity is a neutral element for max. (Or the smallest long if you work with longs). Alternatively you can represent your value as e

Re: help needed to use reducers and monoid

2012-08-19 Thread nicolas.o...@gmail.com
> > How do I construct a combining fn out of 'max-key' and is there an idiom or > a pattern for doing so? You might use the fact that -Infinity is a neutral element for max. (Or the smallest long if you work with longs). Alternatively you can represent your value as either a number or nil, nil bei