Skip to content

Instantly share code, notes, and snippets.

@klaeufer
Created November 25, 2014 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klaeufer/9a5f525c4170df71d0d5 to your computer and use it in GitHub Desktop.
Save klaeufer/9a5f525c4170df71d0d5 to your computer and use it in GitHub Desktop.
def pi(n: Long): Double = {
var i = 0L
var c = 0L
while (i < n) {
val x = math.random
val y = math.random
if (x * x + y * y <= 1) c += 1
i += 1
}
4.0 * c / n
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment