Skip to content

Instantly share code, notes, and snippets.

@burtlo
Created May 1, 2013 15:53
Show Gist options
  • Save burtlo/5496133 to your computer and use it in GitHub Desktop.
Save burtlo/5496133 to your computer and use it in GitHub Desktop.
class SumOfMultiples
def self.to(input)
new(3,5).to(input)
end
def initialize(*params)
@params = params
end
def to(input)
all_multiples = []
@params.each do |param|
all_multiples += multiples_upto(param,input)
end
total(all_multiples.uniq)
end
def multiples_upto(multiple,input)
all_multiples = []
current_multiple = multiple
while input > current_multiple
all_multiples.push(current_multiple)
current_multiple += multiple
end
all_multiples
end
def total(multiples)
total = 0
multiples.each do |multiple|
total += multiple
end
total
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment