Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,7 @@
|
|||
(defn calc-pi [iterations]
|
||||
(loop [x (rand) y (rand) in 0 total 1]
|
||||
(if (< total iterations)
|
||||
(recur (rand) (rand) (if (<= (+ (* x x) (* y y)) 1) (inc in) in) (inc total))
|
||||
(double (* (/ in total) 4)))))
|
||||
|
||||
(doseq [x (take 5 (iterate #(* 10 %) 10))] (println (str (format "% 8d" x) ": " (calc-pi x))))
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
(defn experiment
|
||||
[]
|
||||
(if (<= (+ (Math/pow (rand) 2) (Math/pow (rand) 2)) 1) 1 0))
|
||||
|
||||
(defn pi-estimate
|
||||
[n]
|
||||
(* 4 (float (/ (reduce + (take n (repeatedly experiment))) n))))
|
||||
|
||||
(pi-estimate 10000)
|
||||
Loading…
Add table
Add a link
Reference in a new issue