Re: Puzzle solving in Clojure

2016-04-14 Thread Olivier Scalbert
Whooww that is impressive ! Respect !!! Olivier -- 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 Note that posts from new members are moderated - please be patient with your first post. T

Re: Puzzle solving in Clojure

2016-04-14 Thread bernardH
Hi ! On Friday, April 8, 2016 at 3:28:55 PM UTC+2, Olivier Scalbert wrote: > > Hello everybody ! > > I just start learning Clojure and I am a complete newbie ! > > I have tried to solve this classical small puzzle with Clojure. > Assign one digit from {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} to each letter

Re: Puzzle solving in Clojure

2016-04-13 Thread Olivier Scalbert
Thanks to all of you ! There are so much material in your answers that I need to wait this week-end to do some tests ! Clojure is cool ! -- 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 No

Re: Puzzle solving in Clojure

2016-04-13 Thread Ashish Negi
Thanks puzzler for the explanation. I tried out your `unchunk` and its works nicely.. I then googled around about chunk and memory issues.. I found most issues about chunking and stack overflow.. here.. https://stuartsierra.com/2015/04/26/clojure-donts-concat [which is very good read for

Re: Puzzle solving in Clojure

2016-04-12 Thread Mark Engelberg
The points the others have made are true, but not likely the true cause of your memory blow-up. I believe the real source of your problem has to do with Clojure's use of chunked sequences rather than truly lazy sequences, which can bite you in scenarios like this one. (range 10) produces a single

Re: Puzzle solving in Clojure

2016-04-12 Thread Bobby Eickhoff
doall holds on to the head of the seq, "causing the entire seq to reside in memory at one time." (https://clojuredocs.org/clojure.core/doall) Instead, just find the first solution: (->> (permutations (range 10)) (filter check?) (first) (print-solution)) On Friday, April 8, 2016 at 9:28:55

Re: Puzzle solving in Clojure

2016-04-12 Thread Cornelius Goh
Thanks Gary for the explanation on "recur" in "TCE only" situation. -- 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 Note that posts from new members are moderated - please be patient with y

Re: Puzzle solving in Clojure

2016-04-12 Thread Gary Verhaegen
On 12 April 2016 at 14:58, Cornelius Goh wrote: > True. Clojure doesn't provide tail call optimization. According to Daniel > Higginbotham book "Clojure for the Brave and True" (Page 102) he suggests > using "recur" for performance reasons. > > That is, in Olivier's original code, (sorry, withou

Re: Puzzle solving in Clojure

2016-04-12 Thread Cornelius Goh
True. Clojure doesn't provide tail call optimization. According to Daniel Higginbotham book "Clojure for the Brave and True" (Page 102) he suggests using "recur" for performance reasons. That is, in Olivier's original code, (sorry, without understanding his puzzle): (defn permutations [s]

Re: Puzzle solving in Clojure

2016-04-12 Thread Ashish Negi
@Cornelius Goh According to my current understanding.. Tail Call Optimization comes in picture when the `recursive-call`'s return value is not used after its return. Then we do not need the stack.. But my permutation is not like that.. and hence can not be Tall-Call-Optimized.. -- You received

Re: Puzzle solving in Clojure

2016-04-12 Thread Cornelius Goh
continued my above reply... read the "factorial" example in the Wikipedia on tail recursion to save space and time. Hope it helps! -- 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 Note tha

Re: Puzzle solving in Clojure

2016-04-12 Thread Cornelius Goh
https://en.m.wikipedia.org/wiki/Tail_call Tail call optimization... -- 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 Note that posts from new members are moderated - please be patient with

Re: Puzzle solving in Clojure

2016-04-11 Thread Olivier Scalbert
Thanks for your help. I have replaced "my" permutations by "your" permutations code. It works faster (16s against 20 or 24s). And it seems to consume much less memory. Now, I will try to understand how it works, which is another story (for me of course!). -- You received this message becaus

Re: Puzzle solving in Clojure

2016-04-10 Thread Ashish Negi
Though i am not totally sure why it is working.. How removing repeated calls solved the problem of memory ? Other difference is not using `for` loop.. Do post your findings.. if you get it. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to

Re: Puzzle solving in Clojure

2016-04-10 Thread Ashish Negi
Your permutations is being called again for similar inputs.. Try using this and see that similar inputs like (2 3) are coming again for (permutations [1 2 3 4]) (defn permutations [s] (prn s) ;; This will print input (lazy-seq (if (seq (rest s)) (apply concat (for [x s]

Puzzle solving in Clojure

2016-04-09 Thread Cornelius Goh
Just my 2-cent suggestion : at your Permutation recursion function, may be try "recur" instead. -- 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 Note that posts from new members are moder

Puzzle solving in Clojure

2016-04-08 Thread Olivier Scalbert
Hello everybody ! I just start learning Clojure and I am a complete newbie ! I have tried to solve this classical small puzzle with Clojure. Assign one digit from {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} to each letter {o n e t h r l v w y} so that one + one + one + three + three + eleven = twenty Here i