My first ever Programming Puzzles & Code Golf is the Seven-Slash Display. Here is my first Challenge, also based on 7-segment display.
I often think about, besides numbers, what kind of letters I can display using a simple 7 segment display. Turns out a lot of letters can be displayed. In fact, all but the letters K, M, V, W, X can be displayed using a single 7-segment display. This is because you can display either lower case or the upper case of a letter. e.g.
"abcdef" can be displayed as
_ _ _ _
!_!!_ ! _!!_ !_
! !!_!!_ !_!!_ !
Note that each character is a 3x3 matrix made up of !
and _
.
Of course, the 7-segment display can be used to display numbers and symbols:
_ _ _ _ _ _ _
! _ !_ !_ ! _! !!_ !_!! !_!!_!
! _!!_ !_! !_! ! _!! !_ ! ! _!
Some letters can have both upper and lower case:
_ _
! _ !_!!_ ! ! ! _ ! !
!_ !_ ! !! ! ! !!_!!_!!_!!_!
Here are the full set of characters:
_ _ _ _ _ _ _ _ _
! ! ! _! _!!_!!_ !_ !!_!!_! _ !_ _ _ _!
!_! !!_ _! ! _!!_! !!_! _! !_ ! ! !!_!!_! !
_ _ _ _ _ _ _ _ _ _
!_!!_ ! _!!_ !_ ! !_! ! !! _ ! !!_!!_! _ !_ !_ ! !!_! _!
! !!_!!_ !_!!_ ! !_!! ! !!_!!_ ! !!_!! !! _!!_ !_! _!!_
Pay attention that there are a white space(
), a dash(-
) and a question mark(?
). The letter I
, O
and Z
are the same as numbers 1
, 0
and 2
respectively.
In this challenge, you will write a program or a function to display a string using 7-segment display format above.
Rules
You can write a program or a function
This is code-golf, the shortest code in bytes wins
Your program or function should take input from STDIN or as a parameter. And outputs a string to STDOUT or as a string in 3 lines without leading space but terminated with newline. Handle upper/lower case of
CHIOU
properly.You may optionally print trailing white spaces
You must follow the format above. Using underscore
_
and exclamation mark!
to form your 7-segment display.You must support white space(
-
) and question mark (?
)If the string contain unsupported character (k, m, v, w, x), a single error character (3 horizon line, see example) is displayed. Besides the 5 unsupported characters, you can assume the input is made up of only supported character set.
I opted to not have a letter for lowercase L (
l
) due to confusions but if you are so inclined, you can display it like a1
either to the right or left.
Examples
$./a.out Start
_ _
!_ !_ !_! _ !_
_!!_ ! !! !_
$./a.out "7-seg dIsplay"
_ _ _ _ _ _ _
! _ !_ !_ ! _! !!_ !_!! !_!!_!
! _!!_ !_! !_! ! _!! !_ ! ! _!
$./a.out "0123456789 chiou-?"
_ _ _ _ _ _ _ _ _
! ! ! _! _!!_!!_ !_ !!_!!_! _ !_ _ _ _!
!_! !!_ _! ! _!!_! !!_! _! !_ ! ! !!_!!_! !
$./a.out "ABCDEFGHIJLNOPQRSTUZ"
_ _ _ _ _ _ _ _ _ _
!_!!_ ! _!!_ !_ ! !_! ! !! _ ! !!_!!_! _ !_ !_ ! ! _!
! !!_!!_ !_!!_ ! !_!! ! !!_!!_ ! !!_!! !! _!!_ !_!!_
$./a.out "abcdefghijlnopqrstuz"
_ _ _ _ _ _ _ _
!_!!_ _ _!!_ !_ ! !_ !! _ _ !_!!_! _ !_ !_ _!
! !!_!!_ !_!!_ ! !_!! ! !!_!!_ ! !!_!! !! _!!_ !_!!_
$./a.out "Bad Form"
_
_
_
$./a.out "Hello"
_
!_!!_ ! ! _
! !!_ !_ !_ !_!
$./a.out "World"
_
_
_
k, m, v, w, x
do not get displayed. \$\endgroup\$\r
) with line feed (LF,\n
). *nix uses LF and Windows uses CRLF. Only certain legacy systems use CR by itself. More information here: en.wikipedia.org/wiki/Newline \$\endgroup\$