Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
19
Task/Knuths-algorithm-S/Clojure/knuths-algorithm-s-1.clj
Normal file
19
Task/Knuths-algorithm-S/Clojure/knuths-algorithm-s-1.clj
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
(defn s-of-n-fn-creator [n]
|
||||
(fn [[sample iprev] item]
|
||||
(let [i (inc iprev)]
|
||||
(if (<= i n)
|
||||
[(conj sample item) i]
|
||||
(let [r (rand-int i)]
|
||||
(if (< r n)
|
||||
[(assoc sample r item) i]
|
||||
[sample i]))))))
|
||||
|
||||
(def s-of-3-fn (s-of-n-fn-creator 3))
|
||||
|
||||
(->> #(reduce s-of-3-fn [[] 0] (range 10))
|
||||
(repeatedly 100000)
|
||||
(map first)
|
||||
flatten
|
||||
frequencies
|
||||
sort
|
||||
println)
|
||||
Loading…
Add table
Add a link
Reference in a new issue