Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View 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")))

View file

@ -0,0 +1,11 @@
(defn combinations
"Generate the combinations of n elements from a list of [0..m)"
[m n]
(let [xs (range m)]
(loop [i (int 0) res #{#{}}]
(if (== i n)
res
(recur (+ 1 i)
(set (for [x xs r res
:when (not-any? #{x} r)]
(conj r x))))))))