On Nov 8, 2010, at 3:11 PM, Ken Wesson wrote:

> (defn new-gen [a]
>  (distinct #(= (:val %1) (:val %2))
>    (for [f a
>          n [(transform-left f) (transform-right f)]
>          :when (not (contains? #(= (:val n) %) (map :val (parents n))))]
>      n)))
> 
> is more functional but possibly slower.

This is nice, and it's actually very similar to one of my first attempts, as I 
used 'for' too, but I couldn't figure out how to use just a single 'for'. I 
didn't know that you could do that secondary assignment for 'n' like that. This 
is one of my favorite solutions I think.

> If you really just want the first one in traversal order with each
> distinct value, though, you could just use
> 
> (defn new-gen [a]
>  (distinct #(= (:val %1) (:val %2))
>    (apply concat
>      (for [f a]
>          [(transform-left f) (transform-right f)]))))
> 
> which makes distinct do all the heavy lifting (the whole rest of it is
> just the traversal).

This seems to be missing the check for the rule #1 (making sure the parents 
don't have the same value) though...

Thanks for your solutions! It's very helpful for learning Clojure.

- Greg

> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to