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.
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:
For reference, here is the complete character set, a 5x7 bitmap, with a ruler provided for reference purposes only:
My first take, a straight up approach, which is 272 characters without line breaks required here for readability.
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.X XXXX XXXX X X X X X X X X X XXXX XXXX X X X X X X X X X XXXX
For reference, here is the complete character set, a 5x7 bitmap, with a ruler provided for reference purposes only:
Sample Code---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- | 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
My first take, a straight up approach, which is 272 characters without line breaks required here for readability.
As you can see, there is substantial room for improvement.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/;$_ }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: (Golf) LED Sign
by srawls (Friar) on Jun 08, 2001 at 05:59 UTC | |
by tadman (Prior) on Jun 08, 2001 at 06:05 UTC | |
by dws (Chancellor) on Jun 08, 2001 at 06:09 UTC | |
by srawls (Friar) on Jun 08, 2001 at 06:09 UTC | |
by tadman (Prior) on Jun 08, 2001 at 06:12 UTC | |
by petral (Curate) on Jun 10, 2001 at 06:39 UTC | |
(tye)Re: 186- (Golf) LED Sign
by tye (Sage) on Jun 08, 2001 at 11:42 UTC | |
by tye (Sage) on Jun 08, 2001 at 18:39 UTC | |
Ah, but what about correct display of the decimal point?
by mugwumpjism (Hermit) on Jun 08, 2001 at 19:35 UTC | |
by Anonymous Monk on Nov 23, 2007 at 17:43 UTC | |
Re: (Golf) LED Sign
by petral (Curate) on Jun 10, 2001 at 05:49 UTC | |
by tadman (Prior) on Jun 11, 2001 at 05:02 UTC |
Back to
Meditations