0

I'm working towards a tuples function, which takes collections and a parameter n. The parameter designates the number of indices the generated vector should have. The function then permutes all possible n-tuples of the elements in the collection.

So far I've been trying to combine functions from tuples.core and math.combinatoris, namely, tuples and permutations.

  (defn Tuples [& args]
        (combo/permutations (tuple args))) 

Example)

input: (0,1) n=3

output: [[0,0,0] [0,0,1] [0,1,0] [1,0,0] [0,1,1] [1,1,0] [1,0,1] [1,1,1]]

sunspots
  • 1,047
  • 13
  • 29
  • It's not exactly clear what you're asking for here. Can you add some more context? For example, sample input and desired output. – JohnJ Nov 13 '13 at 18:39

1 Answers1

1

What you are looking for is clojure.math.combinatorics/selections:

(require '[clojure.math.combinatorics :as c])

(c/selections [0 1] 3)
;=> ((0 0 0) (0 0 1) (0 1 0) (0 1 1) (1 0 0) (1 0 1) (1 1 0) (1 1 1))
ponzao
  • 20,684
  • 3
  • 41
  • 58