Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 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)
|
||||
1
Task/Knuths-algorithm-S/Clojure/knuths-algorithm-s-2.clj
Normal file
1
Task/Knuths-algorithm-S/Clojure/knuths-algorithm-s-2.clj
Normal file
|
|
@ -0,0 +1 @@
|
|||
([0 29924] [1 30053] [2 30018] [3 29765] [4 29974] [5 30225] [6 30082] [7 29996] [8 30128] [9 29835])
|
||||
5
Task/Knuths-algorithm-S/Clojure/knuths-algorithm-s-3.clj
Normal file
5
Task/Knuths-algorithm-S/Clojure/knuths-algorithm-s-3.clj
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
(defn s-of-n-creator [n]
|
||||
(let [state (atom [[] 0])
|
||||
s-of-n-fn (s-of-n-fn-creator n)]
|
||||
(fn [item]
|
||||
(first (swap! state s-of-n-fn item)))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue