Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Since my former attempt at proposing a Golf was a dismal failure, for a refereshing change, how about something that isn't NP-Complete? This particular function, as with any Perl Golf, should allow for suitable creative expression. TMTOWTDI as always.

The Goal
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.

An example is: print f("19.2");
Which would display:
X XXXX XXXX X X X X X X X X X XXXX XXXX X X X X X X X X X XXXX
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.

For reference, here is the complete character set, a 5x7 bitmap, with a ruler provided for reference purposes only:
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- | 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
Sample Code
My first take, a straight up approach, which is 272 characters without line breaks required here for readability.
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/;$_ }
As you can see, there is substantial room for improvement.

In reply to (Golf) LED Sign by tadman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (9)
    As of 2014-08-28 06:17 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (257 votes), past polls