r/dailyprogrammer • • Sep 15 '12
[9/15/2012] Challenge #98 [difficult] (Reading digital displays)
Challenge #92 [easy] involved converting a number to a seven segment display representation (of a variable size) using +, -, and |. Assume the font looks like this:
+ +--+ +--+ + + +--+ +--+ +--+ +--+ +--+ +--+
| | | | | | | | | | | | | |
| | | | | | | | | | | | | |
+ +--+ +--+ +--+ +--+ +--+ + +--+ +--+ + +
| | | | | | | | | | | | |
| | | | | | | | | | | | |
+ +--+ +--+ + +--+ +--+ + +--+ +--+ +--+Write a program that reads such a string and converts it back into a number. (You'll have to deduce the size yourself.) The output for the above text would be 1234567890.
As a bonus, have your program be able to read a file containing characters of different sizes, like this:
+-+ + + +-+
| | | |
+-+ | | +-+
| +--+ |
+-+ | +-+
|
+
16
Upvotes
5
u/skeeto -9 8 Sep 15 '12 edited Sep 15 '12
This sort-of works. It's a shell script using GOCR and ImageMagick.
The output on the first example (all the numbers),
1234561__0This is the intermediate image that GOCR sees:
If GOCR can't do it, then I highly doubt I could do it myself.
4
u/pdewacht 0 1 Sep 15 '12
Haskell solution. Can handle characters of different sizes.
2
u/rainman002 Sep 16 '12 edited Sep 16 '12
A lot like pdewacht's, but in Python, and reads data from stdin, and handles varying size.
Code in pastebin, 651 chars.
2
u/mktange Sep 23 '12
Here is my Python version which uses binary encoding to read the 7-segment digital displays. It can handle different sizes.
1
u/Riddlerforce Sep 15 '12
Without using a text to image library, how would you do it? I'm a bit at a loss here.
I'm thinking about reading the file into a grid of characters (or just pretending it's a grid of characters, since you know exactly how long each line is).
Then, starting from the upper right hand corner, recursively determine which lines there are, with tree branch nodes being the + signs and the base case being either the edge of a digital digit or a space.
But this seems like such an elementary way to do it. Is there a better way?
1
u/CMahaff Sep 16 '12
Go - Can handle different sizes, but the file must be "perfectly whitespaced. I.E. the bonus given must have whitespace on the four's tail to match up with the end of the 5 or the 5 will be ignored.
EDIT: Likely very inefficent
1
u/AsdfUser Sep 19 '12
C#, can handle digits of different sizes: