Skip to content

Instantly share code, notes, and snippets.

@meltedlilacs
Created March 19, 2015 22:35
Show Gist options
  • Save meltedlilacs/dea8de9a2eb052f913f9 to your computer and use it in GitHub Desktop.
Save meltedlilacs/dea8de9a2eb052f913f9 to your computer and use it in GitHub Desktop.
PI
def pi(terms)
puts 4 * ((1..terms).inject(0) {|sum, x| sum + (((x%2==0) ? -1.0 : 1.0) / (2*x - 1))})
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment