<?xml version="1.0" encoding="windows-1252"?>
<node id="86805" title="(Golf) LED Sign" created="2001-06-08 00:22:41" updated="2005-08-14 22:25:45">
<type id="120">
perlmeditation</type>
<author id="49599">
tadman</author>
<data>
<field name="doctext">
Since my [id://82512|former attempt] at proposing a Golf was a
dismal failure, for a refereshing change, how about something
that isn't &lt;A HREF="http://hissa.nist.gov/dads/HTML/npcomplete.html"&gt;NP-Complete&lt;/A&gt;?
This particular function, as with any Perl Golf, should allow for suitable
creative expression. TMTOWTDI as always.
&lt;BR&gt;
&lt;BR&gt;
&lt;B&gt;The Goal&lt;/B&gt;
&lt;BR&gt;
Create a function which when given a numeric string, returns
a multi-line string which is the equivalent 7-segment display
output, as one might find on a cash register or digital watch.
No external modules should be used. No requirement for
compatibility with 'strict' or '-w', but the function must
operate properly if called more than one time from within
the same program.
&lt;BR&gt;
&lt;BR&gt;
&lt;READMORE&gt;
An example is:
&lt;CODE&gt;print f("19.2");
&lt;/CODE&gt;
Which would display:
&lt;CODE&gt;   X XXXX      XXXX
   X X  X         X
   X X  X         X
   X XXXX      XXXX
   X    X      X   
   X    X      X   
   X    X    X XXXX
&lt;/CODE&gt;
Any combination of the characters 0-9, '-', or '.' are valid.
Any other characters are ignored. 7 lines of text are always
returned by the function, though these lines may be blank if
no input was provided that was valid.
&lt;BR&gt;
&lt;BR&gt;
For reference, here is the complete character set, a 5x7
bitmap, with a ruler provided for reference purposes only:
&lt;CODE&gt;  ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
| XXXX    X XXXX XXXX X  X XXXX XXXX XXXX XXXX XXXX        
| 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    X XXXX XXXX XXXX XXXX XXXX    X XXXX XXXX      XXXX
| 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        
| XXXX    X XXXX XXXX    X XXXX XXXX    X XXXX XXXX    X   
&lt;/CODE&gt;
&lt;B&gt;Sample Code&lt;/B&gt;&lt;BR&gt;
My first take, a straight up approach, which
is 272 characters without line breaks required
here for readability.
&lt;CODE&gt;sub f{
my@c=qw[00700 00001 00000 75557 11111 71747
71717 55711 74717 74757 71111 75757 75717];
my@l,$i;map{$l[$i++%5].=join'',(unpack("B8"
,chr)=~/(.)(.)(.)$/)[0,1,1,2],' '}map{split
//,$c[ord($_)-45]}grep{/[0-9\.\-]/}split//,
pop;$_=join'',map{"$_\n"}@l[0,1,1,2,3,3,4];
tr/01/ X/;$_
}
&lt;/CODE&gt;
As you can see, there is substantial room for improvement.
</field>
</data>
</node>
