Skip to content

Instantly share code, notes, and snippets.

@v-kolesnikov
Last active December 1, 2016 21:12
Show Gist options
  • Select an option

  • Save v-kolesnikov/9740d6bc6f8e5b9b36c70256559c2bd8 to your computer and use it in GitHub Desktop.

Select an option

Save v-kolesnikov/9740d6bc6f8e5b9b36c70256559c2bd8 to your computer and use it in GitHub Desktop.
module Led
DIGITS = {
0 => [' _ ',
'| |',
'|_|'],
1 => [' ',
' | ',
' | '],
2 => [' _ ',
' _|',
'|_ '],
3 => [' _ ',
' _|',
' _|'],
4 => [' ',
'|_|',
' |'],
5 => [' _ ',
'|_ ',
' _|'],
6 => [' _ ',
'|_ ',
'|_|'],
7 => [' _ ',
' |',
' |'],
8 => [' _ ',
'|_|',
'|_|'],
9 => [' _ ',
'|_|',
' _|']
}.freeze
class << self
def to_led(n)
digits = n.to_s.split('').map(&:to_i).map(&DIGITS)
(0..2).map { |line| digits.map { |d| d[line] }.join(' ') }
end
end
end
puts Led.to_led(2017)
# _ _ _
# _| | | | |
# |_ |_| | |
# => nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment