13
1
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(
), dash(
-
) 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"
_
_
_
Yes, you can assume there is no unsupported symbols. My intention is to make sure strings containing
k, m, v, w, x
do not get displayed. – some user – 2015-07-29T06:29:14.7571
Related: http://codegolf.stackexchange.com/questions/9266/emulate-a-7-segment-display
– DavidC – 2015-07-29T07:45:24.063I think you confused carriage return (CR,
– Winny – 2015-07-29T08:36:17.087\r
) with line feed (LF,\n
). *nix uses LF and Windows uses CRLF. Only certain legacy systems use CR by itself. More information here: https://en.wikipedia.org/wiki/NewlineYour "8" character seems to have a bar "|" instead of an exclamation mark "!". Is it intended? – coredump – 2015-07-29T13:20:25.577
Oops! I goofed. I will fix that! – some user – 2015-07-29T15:03:52.450
1@Winny, you are right of course. I was too lazy to look it up when I wrote it. – some user – 2015-07-29T15:04:54.953
Y
ike! Thanks! – some user – 2015-07-29T17:19:02.433Hey, I was thinking about 7 digit alphabets a lot and here are ideas for a full alphabet (the letters below the 'main' letters are just alternatives), not all the letters are that nice but I think some of them might do well. here the image
– flawr – 2015-08-03T12:44:51.960Glad to see someone with the same interest! I like the way you defined
V
. IMO, the most difficult alphabet isX
. It is just not possible to display it without some sort of diagonal segment. – some user – 2015-08-04T00:14:47.480Why doesn't 'a' have a lowercase representation? All segments on, except the top-left segment... – agtoever – 2015-09-27T05:42:23.623