Created
December 3, 2012 18:35
-
-
Save nickserv/4196946 to your computer and use it in GitHub Desktop.
Harmonic Series in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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