Created
December 11, 2016 22:18
-
-
Save descartez/914afe87a0248dceebc5e102bb33a35b to your computer and use it in GitHub Desktop.
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
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