Skip to content

Instantly share code, notes, and snippets.

@mauroporras
Last active January 8, 2016 17:54
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/9509c6ee2da6aa932a23 to your computer and use it in GitHub Desktop.
Save mauroporras/9509c6ee2da6aa932a23 to your computer and use it in GitHub Desktop.
#!/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