Last active
January 8, 2016 17:54
-
-
Save mauroporras/9509c6ee2da6aa932a23 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
#!/usr/bin/env ruby | |
class Fixnum | |
def holes | |
if abs > 9 | |
to_s.chars.reduce(0) { |a, e| a += e.to_i.holes } | |
else | |
case self | |
when 1, 2, 3, 5, 7 | |
0 | |
when 0, 4, 6, 9 | |
1 | |
else | |
2 | |
end | |
end | |
end | |
end | |
5.times do | |
n = (1..1_000_000).to_a.sample | |
puts "#{n}: #{n.holes}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment