22
2
Art stolen from What size is the digit?
7-segment digits can be represented in ASCII using _|
characters. Here are the digits 0-9
:
_ _ _ _ _ _ _ _
| | | _| _| |_| |_ |_ | |_| |_|
|_| | |_ _| | _| |_| | |_| _|
Your job is to parse the art into normal numbers.
Notes on numbers
- Each digit has a different width.
1
has a width of1
3
and7
are2
wide245689
and0
are all3
wide
Also between each digit is one char of padding. Here is the full char set:
// <-- should be one space, but SE formatting messed it up | | ------------- _ _| |_ ------------- _ _| _| ------------- |_| | ------------- _ |_ _| ------------- _ |_ |_| ------------- _ | | ------------- _ |_| |_| ------------- _ |_| _| ------------- _ | | |_|
Input
Input can be either from the console or as a string arg to a function.
Output
Output is either put to the console or is returned from the function.
Examples:
_ _ _
| | | |_
| | | |_|
1776
_ _ _
_| | | | |_
|_ |_| | |_|
2016
_ _
| |_| |_| |_
| _| | _|
1945
_ _ _ _ _ _
| | | | | | | | | | | | |
| |_| |_| |_| |_| |_| |_|
1000000
_ _ _ _ _ _ _ _
| | | _| _| |_| |_ |_ | |_| |_|
|_| | |_ _| | _| |_| | |_| _|
0123456789
This is code-golf so shortest byte count wins!
Related – J Atkin – 2016-02-13T20:48:14.647
I am interested in learning about the best algorithms to solve this kind of problem, and I'm having difficulty learning from the answers here (they're good, just very concise). Is there a place you can refer me to see more lengthy explanations, preferably with pictures? – None – 2016-02-17T01:51:00.377
Well, The way mine works is fairly simple. It transposes the list and loops over it. It then splits on empty lines. Each number is checked against a fingerprint table for each number. The others work a bit like mine, except instead of a fingerprint table they basically have a hash table they use.
– J Atkin – 2016-02-17T01:57:33.997Is there a more general name for this type of problem in computer science? – None – 2016-02-17T02:10:09.500
I have no idea ;) – J Atkin – 2016-02-17T02:57:31.213