CDE
This commit is contained in:
parent
518da4a923
commit
764da6cbbb
6144 changed files with 83610 additions and 11 deletions
20
Task/Combinations/Clojure/combinations.clj
Normal file
20
Task/Combinations/Clojure/combinations.clj
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
(defn combinations
|
||||
"If m=1, generate a nested list of numbers [0,n)
|
||||
If m>1, for each x in [0,n), and for each list in the recursion on [x+1,n), cons the two"
|
||||
[m n]
|
||||
(letfn [(comb-aux
|
||||
[m start]
|
||||
(if (= 1 m)
|
||||
(for [x (range start n)]
|
||||
(list x))
|
||||
(for [x (range start n)
|
||||
xs (comb-aux (dec m) (inc x))]
|
||||
(cons x xs))))]
|
||||
(comb-aux m 0)))
|
||||
|
||||
(defn print-combinations
|
||||
[m n]
|
||||
(doseq [line (combinations m n)]
|
||||
(doseq [n line]
|
||||
(printf "%s " n))
|
||||
(printf "%n")))
|
||||
Loading…
Add table
Add a link
Reference in a new issue