Tail call optimization...
That is, in Olivier's original code, (sorry, without understanding his puzzle):
(defn permutations [s]
(lazy-seq
...
...
(map # (...) (recur (remove #...)))))
...
See if it improves performance by just using "recur" ?
(defn non-tce-fact [n] (if (zero? n) 1 (* n (non-tce-fact (dec n))))) (defn tce-fact ([n] (tce-fact n 1)) ([n p] (if (zero? n) p (recur (dec n) (* n p)))))
(defn- unchunk "Given a sequence that may have chunks, return a sequence that is 1-at-a-time lazy with no chunks. Chunks are good for efficiency when the data items are small, but when being processed via map, for example, a reference is kept to every function result in the chunk until the entire chunk has been processed, which increases the amount of memory in use that cannot be garbage collected." [s] (lazy-seq (when (seq s) (cons (first s) (unchunk (rest s))))))
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
[…]
How can I change the code into a more idiomatic one ?