repo.or.cz
/
ruby-svn.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
history
|
raw
|
HEAD
* io.c (rb_open_file): encoding in mode string was ignored if perm is
[ruby-svn.git]
/
sample
/
pi.rb
blob
63be974285db10e98566eb6cb99a6fdc6516b893
1
#!/usr/local/bin/ruby
2
3
k, a, b, a1, b1 = 2, 4, 1, 12, 4
4
5
loop do
6
# Next approximation
7
p, q, k = k*k, 2*k+1, k+1
8
a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1
9
# Print common digits
10
d = a / b
11
d1 = a1 / b1
12
while d == d1
13
print d
14
$stdout.flush
15
a, a1 = 10*(a%b), 10*(a1%b1)
16
d, d1 = a/b, a1/b1
17
end
18
end