Not so happy with my code

2010-04-18 Thread verec
I have two problems with the following code. First, I have this `tos' business (to-string) because: user=> (first "abc") \a user=> (rest "abc") (\b \c) Since I wanted to get strings out of strings, a character or a collection is no good. Second, I ended-up having to use a mutable atom `res' becaus

Re: Not so happy with my code

2010-04-18 Thread verec
Posted too quickly ... replace "ana3" with "anagram". I cleaned-up the code before posting, forgetting that the previous version "ana3" was still in the REPL ... Oh well ... -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send e

Re: Not so happy with my code

2010-04-18 Thread David Nolen
On Sun, Apr 18, 2010 at 9:20 PM, verec < jeanfrancois.brouil...@googlemail.com> wrote: > I have two problems with the following code. > First, I have this `tos' business (to-string) because: > user=> (first "abc") > \a > user=> (rest "abc") > (\b \c) > Since I wanted to get strings out of strings,

Re: Not so happy with my code

2010-04-18 Thread Per Vognsen
(use 'clojure.contrib.combinatorics 'clojure.contrib.str-utils) (defn anagrams [xs] (map #(str-join "" %) (distinct (permutations xs Of course, the real meat is in the permutations function. The implementation in the combinatorics library is a bit complicated. Here's something simpler