Skip to content

Commit a706a76

Browse files
committed
Add blank lines in Monte Carlo integration in Clojure
1 parent 9ca59fc commit a706a76

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

contents/monte_carlo_integration/code/clojure/monte_carlo.clj

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
(map #(* % %))
99
(reduce +))
1010
(* r r)))
11+
1112
(defn rand-point [r]
1213
"return a random point from (0,0) inclusive to (r,r) exclusive"
1314
(repeatedly 2 #(rand r)))
15+
1416
(defn monte-carlo [n r]
1517
"take the number of random points and radius return an estimate to
1618
pi"
@@ -22,11 +24,12 @@ pi"
2224
(if (in-circle? (rand-point r) r)
2325
(inc count)
2426
count))))))
27+
2528
(defn -main []
2629
(let [constant-pi Math/PI
2730
computed-pi (monte-carlo 10000000 2) ;; this may take some time on lower end machines
2831
difference (Math/abs (- constant-pi computed-pi))
2932
error (* 100 (/ difference constant-pi))]
3033
(println "world's PI: " constant-pi
31-
",our PI: " (double computed-pi)
34+
",our PI: " (double computed-pi)
3235
",error: " error)))

0 commit comments

Comments
 (0)