Last active
August 29, 2015 14:25
-
-
Save noili/bcc8e4c6c0ad7b708b08 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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