Skip to content

Instantly share code, notes, and snippets.

@noili
Last active August 29, 2015 14:25
Show Gist options
  • Select an option

  • Save noili/bcc8e4c6c0ad7b708b08 to your computer and use it in GitHub Desktop.

Select an option

Save noili/bcc8e4c6c0ad7b708b08 to your computer and use it in GitHub Desktop.
class SumOfMultiples
attr_accessor :args
def initialize *args
self.args = args
end
def self.to n
new(3,5).to n
end
def to n
sum = 0
n.times do |x|
sum += x if is_divisible? x
end
sum
end
def is_divisible? x
args.any? { |m| x % m == 0 }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment