Skip to content

Instantly share code, notes, and snippets.

@descartez
Created December 11, 2016 22:18
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 descartez/914afe87a0248dceebc5e102bb33a35b to your computer and use it in GitHub Desktop.
Save descartez/914afe87a0248dceebc5e102bb33a35b to your computer and use it in GitHub Desktop.
def multiples_up_to(multiple, limit)
# Rather than calculate every number and evaluate whether that number is a multiple, there's a handy bit of math I found that checks how many multiples are in any number of integers.
# We then keep adding up the "multiple", doing basic arithmetic until we reach the limit
start = 0
((limit - multiple + 1)/multiple).times do
start += multiple
p start
end
end
multiples_up_to(3,200)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment