Being completely new to clojure, I am still struggling with my features. If I have 2 lists, say "1234" and "abcd", I need to make all possible ordered lists of length 4. The output I want is for length 4:
("1234" "123d" "12c4" "12cd" "1b34" "1b3d" "1bc4" "1bcd" "a234" "a23d" "a2c4" "a2cd" "ab34" "ab3d" "abc4" "abcd")
where 2 ^ n in the amount depending on the inputs.
I wrote the following function to randomly wander one line / list. The argument [par] will be similar to ["1234" "abcd"]
(defn make-string [par] (let [c1 (first par) c2 (second par)] ;version 3 0.63 msec (apply str (for [loc (partition 2 (interleave c1 c2)) :let [ch (if (< (rand) 0.5) (first loc) (second loc))]] ch))))
The output will be 1 of the 16 ordered lists above. Each of the two input lists will always be of equal length, for example, 2,3,4,5, up to 2 ^ 38 or within the limits of the available plunger. In the function above, I tried changing it to create all ordered lists, but failed. Hope someone can help me. Thanks.
source share