Skip to content

Instantly share code, notes, and snippets.

@nickserv
Created December 3, 2012 18:35
Show Gist options
  • Save nickserv/4196946 to your computer and use it in GitHub Desktop.
Save nickserv/4196946 to your computer and use it in GitHub Desktop.
Harmonic Series in Ruby
# Set the sum to 0 initially and print its value
p sum = 0
# Set i to 0 initially
i = 1
# Start an infinite, iterative loop
loop do
# Add 1/i (as a float to keep this accurate) to sum and print its new value
p sum += 1/i.to_f
# Increment i by 1
i += 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment