Last active
October 6, 2015 22:24
-
-
Save mauroporras/b87d071eba573bc26f6c 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
class Fixnum | |
def is_zero_one? | |
self.to_s.chars.all? { |e| '01'.include? e } | |
end | |
def smallest_zero_one | |
unless (1...100_000).include?(self) | |
fail ArgumentError.new('Integer should be between 1 and 99,999') | |
end | |
self * (1..Float::INFINITY).find { |c| (self * c).is_zero_one? } | |
end | |
end | |
puts 4.smallest_zero_one | |
puts 10.smallest_zero_one | |
puts 40.smallest_zero_one | |
puts 101.smallest_zero_one | |
puts 100_000.smallest_zero_one |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment