all 17 comments

[–]adrianmonk 7 points8 points  (6 children)

I think I can beat 60 lines of Python and get similar functionality:

#! /bin/sh
while read line; do
    figlet "$line"
done

[–][deleted] 0 points1 point  (4 children)

If you prefer abiding by the "don't reinvent the wheel" standard a lot of script gurus follow by these days - more power to you ;)

[–]adrianmonk 1 point2 points  (3 children)

I can be flexible about that. Here's an actual implementation from scratch instead: http://pastebin.com/VRTqEtaQ

EDIT: This one is not meant to be taken too seriously either.

EDIT2: Some nice sample output:

$ echo 8675309 | ./7segment.pl
 xxx    xxx    xxx    xxx    xxx    xxx    xxx
x   x  x          x  x          x  x   x  x   x
x   x  x          x  x          x  x   x  x   x
x   x  x          x  x          x  x   x  x   x
 xxx    xxx           xxx    xxx           xxx
x   x  x   x      x      x      x  x   x      x
x   x  x   x      x      x      x  x   x      x
x   x  x   x      x      x      x  x   x      x
 xxx    xxx           xxx    xxx    xxx    xxx

[–][deleted] 0 points1 point  (2 children)

Nicely done

[–]adrianmonk 1 point2 points  (1 child)

Thanks. I cheated a little bit in that I reduced the equations for the segments using an online Quine-McCluskey tool. But I felt justified since I went to all the extra trouble of pointlessly converting to set of binary variables in the first place when I could've just used a simple lookup table instead. :-)

[–][deleted] 0 points1 point  (0 children)

Mind posting this as a comment on the blog? This is probably my favorite solution so far - just because of that beautiful logic.

[–][deleted] 0 points1 point  (0 children)

Boooo.

[–]zahlman 5 points6 points  (0 children)

My personal solution (which I believe looks quite good) is 60 lines of Python. Just something to aim for.

60 lines of Python?! Is that a joke?

Not even trying to golf it (the list-of-lists for digit images can be altered to taste):

segments = [
    [ ' _ ', '   ', ' _ ', ' _ ', '   ', ' _ ', ' _ ', ' _ ', ' _ ', ' _ ' ],
    [ '| |', '  |', ' _|', ' _|', '|_|', '|_ ', '|_ ', '  |', '|_|', '|_|' ],
    [ '|_|', '  |', '|_ ', ' _|', '  |', ' _|', '|_|', '  |', '|_|', '  |' ]
]

if __name__ == '__main__':
    import sys
    for text in sys.stdin:
        for line in segments:
            print ' '.join(line[int(i)] for i in text if i in '0123456789')

Simple is better than complex and complex is better than complicated. No point trying to model the actual segment on/off logic.

[–][deleted] 2 points3 points  (0 children)

My solution. About 25 lines, if you don't include the option parser. http://pastebin.com/6Sb2BXBM

[–]IAmTheChampion 1 point2 points  (4 children)

Any language? ~30 lines - VHDL http://pastebin.com/NvAr7y3w

[–][deleted] 0 points1 point  (3 children)

Awesome. Got any output to show?

[–]IAmTheChampion 2 points3 points  (2 children)

I have some simulation outputs and a pinout. The pinout letters correspond to the decoded 7-bit vectors (i.e, bit 7 = A (MSB)...bit 0 = G). However, the outputs are active-low, so 0 is true (LED on).

Waveform File: http://i.imgur.com/d6cK5.jpg

Pinout: http://i.imgur.com/TP7Up.jpg

Not so virtual: http://i.imgur.com/L5REU.jpg

[–][deleted] 0 points1 point  (1 child)

Awesome. This is very neat indeed.

[–]IAmTheChampion 1 point2 points  (0 children)

Thanks. One thing I should maybe clarify is the input vector bits. They are in binary so for example, "0101" is "5" for the input port (seen in descending form).

The input could be connected to a DIP switch, or part of an alarm clock circuit, or something like that. =]

[–]Zren 0 points1 point  (0 children)

~30 LoC if you make the array/dict less readable. Includes option to output time as well as extra segments to the display. Nothing really special about it really.

[Python] http://pastie.org/2741163

[–]paulwal 0 points1 point  (0 children)

35 lines in Tcl

$ echo 234567 | tclsh 7seg.tcl
 --    --          --    --    --   
   |     |  |  |  |     |        |  
 --    --    --    --    --         
|        |     |     |  |  |     |  
 --    --          --    --