On Nov 8, 2010, at 3:37 PM, Laurent PETIT wrote:

> out of curiosity, if 2 siblings have the same value for their :value 
> attribute, you just keep the first one you encounter, and throw away the 
> others with the same :value attribute ?

Yes.

> Is it because they also have the same attributes altogether, or because 
> you're relying on an "importance" criteria based on the position of the 
> siblings within the vector ?
> additional question: can you show us the whole content of a node map/record ?

I think to answer both questions I should explain the context of this problem.

I'm currently in the process of learning Clojure, and as an ex cerise to assist 
in this endeavor I set about solving a problem presented in the classic game 
called Myst.

You see, in Myst, at one point you encounter the following plaque on the wall 
of an observatory:

        http://cl.ly/e9d0d045f851c3efc66c

        (****** spoiler alert!! [it's not too bad...] ********)










The top numbers seem to represent a time, and indeed, if you input that using 
the turn wheels in front of the lighthouse, mechanical gears emerge from the 
ocean allowing you to walk into the lighthouse.

Inside of the lighthouse you will encounter this piece of machinery:

        http://cl.ly/ad609b96310f5717b6a8

The gears are initially set to 3,3,3. Pull the right lever and the top two 
gears will turn, giving you 1,1,3. If instead you had pulled the left lever, 
the bottom two gears turn giving you 3,1,1.

So, from the plaque, you would think that the goal here is to get 2,2,1.

After unsuccessfully pulling the levers for about an hour I decided it was time 
to turn this problem into a Clojure learning exercise.

Having successfully written my function (and now, thanks to Ken and Meikel, 
having written it *properly*), I can assuredly inform you all that this whole 
business is a red herring! There is no possible way to obtain 2,2,1 from any 
series of left or right turns if you're starting at 3,3,3!

So don't bother wasting your time trying it. It's a code for something else. 
Clojure tells me so. :-p

- Greg

> 2010/11/8 Greg <[email protected]>
> So... I tried, and failed, to use transients properly.
> 
> The function below, new-gen, takes a sequence of "nodes" and creates a new 
> generation of nodes out of them using the functions "transform-left" and 
> "transform-right".
> 
> Each node in the sequence has two children, one is created with 
> transform-left, the other with tranform-right.
> 
> The desired result is a new sequence containing all the children, 
> representing the "new generation".
> 
> The catch is that some of the children are aborted at birth according the 
> following rules:
> 
> 1) If the child has an existing parent with a value equal to its own, it is 
> left out of the sequence
> 2) If the child has an existing sibling with a value equal to its own, it too 
> is left out of the resultant sequence
> 
> The function is listed below:
> 
> (defn new-gen [a]
>       (let [t (transient [])]
>               (doseq [f a]
>                       (doseq [n [(transform-left f) (transform-right f)]]
>                               (when-not (contains? #(= (:val n) %) (map :val 
> (parents n)))
>                                       (conj! t n)))) ;; <-- transient 
> bashing!!
>               (distinct #(= (:val %1) (:val %2)) (persistent! t))))
> 
> I'm also using modified versions of 'distinct' and 'contains?', the full 
> source for them (and the new-gen function) is available in 
> syntax-hightlighted goodness here:
> 
>       http://paste.pocoo.org/show/288063/
> 
> 
> The question is: how do I write new-gen in an elegant way and avoid "bashing 
> the transient"?
> 
> I must say it would be really nice if this was considered kosher.. as it does 
> work just fine. It would also be useful to know why transient bashing is 
> frowned upon.
> 
> Any help is greatly appreciated!
> 
> - 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

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