Sum of a series

say sum(1..1000, {|n| 1 / n**2 })

Alternatively, using the reduce{} method:

say (1..1000 -> reduce { |a,b| a + (1 / b**2) })

Output:

1.64393456668155980313905802382221558965210344649

Last updated