Created
February 10, 2012 20:31
-
-
Save dinedal/1792558 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def zipflaw(x, i) | |
j = 0 | |
k = 1 | |
i.times do | |
# I was stuck for awhile because I wasn't using floating points and the error was enough to move my answer back by 2 ranks! | |
j += x.to_f/k.to_f | |
k += 1 | |
end | |
j | |
end | |
zipflaw(2520,900) | |
# => 18598.01801986991 | |
zipflaw(2520,900) / 2 | |
# => 9299.009009934955 | |
zipflaw(2520,22) | |
# => 9300.849390547533 | |
# close enough =) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment