Last active
December 1, 2016 21:12
-
-
Save v-kolesnikov/9740d6bc6f8e5b9b36c70256559c2bd8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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