Last active
March 26, 2019 10:28
-
-
Save peter0749/12ef74328cbefae3549c94c7028e6aff to your computer and use it in GitHub Desktop.
Pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val n_pt = 1000000 | |
val rd_g = scala.util.Random | |
(for ( i <- 0 until n_pt ) yield (rd_g.nextFloat, rd_g.nextFloat)).map( x => (x._1-0.5,x._2-0.5) ).map( x => if (x._1*x._1+x._2*x._2<0.25) 1 else 0 ).reduce(_ + _).toFloat / n_pt.toFloat * 4.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment