1 # ----------------------------------------------------------------------
2 # The Great Computer Language Shootout
3 # http://shootout.alioth.debian.org/
5 # Based on D language implementation by Dave Fladebo
7 # Contributed by Anthony Borla
8 # ----------------------------------------------------------------------
10 n
= (ARGV.shift
|| 1).to_i
12 alt
= 1.0 ; s0
= s1
= s2
= s3
= s4
= s5
= s6
= s7
= s8
= 0.0
15 d
= d
.to_f
; d2
= d
* d
; d3
= d2
* d
; ds
= Math
.sin(d
) ; dc
= Math
.cos(d
)
17 s0
+= (2.0 / 3.0) ** (d
- 1.0)
18 s1
+= 1.0 / Math
.sqrt(d
)
19 s2
+= 1.0 / (d
* (d
+ 1.0))
20 s3
+= 1.0 / (d3
* ds
* ds
)
21 s4
+= 1.0 / (d3
* dc
* dc
)
25 s8
+= alt
/ (2.0 * d
- 1.0)
30 printf("%.9f\t(2/3)^k\n", s0
)
31 printf("%.9f\tk^-0.5\n", s1
)
32 printf("%.9f\t1/k(k+1)\n", s2
)
33 printf("%.9f\tFlint Hills\n", s3
)
34 printf("%.9f\tCookson Hills\n", s4
)
35 printf("%.9f\tHarmonic\n", s5
)
36 printf("%.9f\tRiemann Zeta\n", s6
)
37 printf("%.9f\tAlternating Harmonic\n", s7
)
38 printf("%.9f\tGregory\n", s8
)