Created
May 13, 2010 15:37
-
-
Save dannysmith/399961 to your computer and use it in GitHub Desktop.
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
include Math | |
def myPi(reps) | |
inside = 0 | |
reps.times do | |
inside += 1 if (Math.sqrt(rand**2+rand**2) < 1) | |
end | |
return (4*inside)/reps.to_f | |
end | |
puts "Running, please be patient..." | |
pi_values = [] | |
1000.times {pi_values << myPi(14000)} | |
f = File.open("pi.txt", "w") | |
pi_values.each {|i| f.puts i} | |
f.close | |
sum = 0 | |
pi_values.each {|i| sum += i} | |
puts "Success! Data Written to pi.txt..." | |
puts "Pi is about " + (sum/1000).to_s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment