A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
7
Task/Monte-Carlo-methods/Clojure/monte-carlo-methods.clj
Normal file
7
Task/Monte-Carlo-methods/Clojure/monte-carlo-methods.clj
Normal file
|
|
@ -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))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue