On Sun, Dec 28, 2008 at 12:49 AM, bOR_ <boris.sch...@gmail.com> wrote: > > Annoying way to start a morning :P. Thanks though for the tip on > htdp.org
I'm not trying to be annoying. I just don't know how valuable the answer will be to you, until you've got a better handle on recursion. The code below is the main idea; it will give you back a sequence of sequences of characters (you really want to work with sequences as much as possible, and convert to a string in the final step). I changed the name of your input from sets to seqs, since it works with any sequence of sequences, not just sets. (defn expand [seqs] (if (empty? seqs) [nil] (for [letter (first seqs), seq-of-letters (expand (rest seqs))] (cons letter seq-of-letters)))) So now, you've got this really nice reusable piece of code that extracts all possible combinations of something from the first sequence, followed by something from the second, and so on (doesn't even have to be letters, despite the names of the variables). But do you understand why the recursion works? Could you come up with something similar for a new problem? If not, htdp.org will definitely help you get to that point. Anyway, if you want to wrap something around this that is specific to words and characters, it would look like this: (defn expand-to-words [seqs] (map #(apply str %) (expand seqs))) > (expand-to-words ["abcdefg" "ab" "ad"]) ("aaa" "aad" "aba" "abd" "baa" "bad" "bba" "bbd" "caa" "cad" "cba" "cbd" "daa" "dad" "dba" "dbd" "eaa" "ead" "eba" "ebd" "faa" "fad" "fba" "fbd" "gaa" "gad" "gba" "gbd") --~--~---------~--~----~------------~-------~--~----~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---