Skip to content

Instantly share code, notes, and snippets.

@dinedal
Created February 10, 2012 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dinedal/1792558 to your computer and use it in GitHub Desktop.
Save dinedal/1792558 to your computer and use it in GitHub Desktop.
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