0

コレクションとパラメータnを取るタプル関数に向けて取り組んでいます。パラメータは、生成されたベクトルが持つべきインデックスの数を指定します。この関数は、コレクション内の要素のすべての可能な n タプルを並べ替えます。

これまでのところ、tuples.core と math.combinatoris の関数、つまりタプルと順列を組み合わせようとしました。

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

例)

入力: (0,1) n=3

出力: [[0,0,0] [0,0,1] [0,1,0] [1,0,0] [0,1,1] [1,1,0] [1,0, 1] [1,1,1]]

4

1 に答える 1

1

あなたが探しているのは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))
于 2013-11-13T20:39:21.307 に答える