Skip to content

Instantly share code, notes, and snippets.

@mauroporras
Last active October 6, 2015 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauroporras/b87d071eba573bc26f6c to your computer and use it in GitHub Desktop.
Save mauroporras/b87d071eba573bc26f6c to your computer and use it in GitHub Desktop.
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