![]() |
Out of Egypt:Halfway to the Promised Land"God is a place you will wait for the rest of your life." |
July 20, 2008
fun with programming, pt. I: interactive pi in ruby
Here's a little program (pi_calc.rb) I adapted today from the devdaily blog to calculate the value of pi using the converging series
4/1 - 4/3 + 4/5 - 4/7 + 4/9 ....
The original program wasn't interactive so you had to keep editing the code just to see how much more accurate the calculation got as you went farther into the series. I fixed that.
You should be able to run the program on Mac OS X or on any other Unix-y system that has Ruby installed in /usr/bin. Just open the Terminal, go to the directory to which you've downloaded the script (by using cd), and type ./pi_calc.rb
If it doesn't work for you, try doing a chmod 755 pi_calc.rb in the directory to which you downloaded the script. Beyond that, I can make no guarantees about the performance of my code. It's the first Ruby script I've ever written.
Posted by donovan at 11:28 AM | Category: Technology
