First commit of partial RosettaCode contents.
Pushing this for testing purposes. Lots of work still needed.
This commit is contained in:
commit
1e05ecd7ee
781 changed files with 9080 additions and 0 deletions
28
Task/Pi/Ruby/pi-2.rb
Normal file
28
Task/Pi/Ruby/pi-2.rb
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
def pi
|
||||
q, r, t, k, n, l = 1, 0, 1, 1, 3, 3
|
||||
dot = nil
|
||||
loop do
|
||||
if 4*q+r-t < n*t
|
||||
yield n
|
||||
if dot.nil?
|
||||
yield '.'
|
||||
dot = '.'
|
||||
end
|
||||
nr = 10*(r-n*t)
|
||||
n = ((10*(3*q+r)) / t) - 10*n
|
||||
q *= 10
|
||||
r = nr
|
||||
else
|
||||
nr = (2*q+r) * l
|
||||
nn = (q*(7*k+2)+r*l) / (t*l)
|
||||
q *= k
|
||||
t *= l
|
||||
l += 2
|
||||
k += 1
|
||||
n = nn
|
||||
r = nr
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
pi {|digit| print digit; $stdout.flush}
|
||||
20
Task/Pi/Ruby/pi.rb
Normal file
20
Task/Pi/Ruby/pi.rb
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Calculate Pi using the Arithmetic Geometric Mean of 1 and 1/sqrt(2)
|
||||
#
|
||||
#
|
||||
# Nigel_Galloway
|
||||
# March 8th., 2012.
|
||||
#
|
||||
require 'flt'
|
||||
Flt::BinNum.Context.precision = 8192
|
||||
a = n = 1
|
||||
g = 1 / Flt::BinNum(2).sqrt
|
||||
z = 0.25
|
||||
(0..17).each{
|
||||
x = [(a + g) * 0.5, (a * g).sqrt]
|
||||
var = x[0] - a
|
||||
z -= var * var * n
|
||||
n += n
|
||||
a = x[0]
|
||||
g = x[1]
|
||||
}
|
||||
puts a * a / z
|
||||
Loading…
Add table
Add a link
Reference in a new issue