more useful options PerlMonks

### Golf: Seven segment display

by kikuchiyo (Hermit)
 on Jan 18, 2012 at 11:52 UTC Need Help??

kikuchiyo has asked for the wisdom of the Perl Monks concerning the following question:

The problem:

Write a function -- with as few characters as possible -- that, given a positive integer, prints it in a seven segment display style, similar to that found on calculators.

Input:

w(1234567890);

Output:

```    _  _     _  _  _  _  _  _
| _| _||_||_ |_   ||_||_|| |
||_  _|  | _||_|  ||_| _||_|

My best effort so far:

```sub w{for\$;(0..2){say map{substr' _ _|_    | |_|',('030030000054116224
+666421416461'=~/./g)[\$_+\$;*10]*2,3}split//,\$_[0]}}

Replies are listed 'Best First'.
Re: Golf: Seven segment display
by Anonymous Monk on Jan 18, 2012 at 12:25 UTC
http://codegolf.stackexchange.com/questions/997/render-digital-clock-style-numbers
Re: Golf: Seven segment display
by kikuchiyo (Hermit) on Jan 18, 2012 at 12:38 UTC

Better approach:

```sub w{for\$;(-2..0){say map{substr'   _ _|_  |_| |',2*ord(('u\$SR,Z]dmj'
+=~/./g)[\$_])>>-3*\$;&14,3}split//,\$_[0]}}

Applying the ...=~/./g trick (which you already used once inside the map) again:

sub w{for\$;(-2..0){say map{substr'   _ _|_  |_| |',2*ord(('u\$SR,Z]dmj'=~/./g)[\$_])>>-3*\$;&14,3}\$_[0]=~/./g}}

I think my idea is a "cul-de-sac" but this is a little bit shorter (7 char.).
```sub w{for\$;(1005,924745596,341831533){say map{\$;>>\$_&1?/../?'|':_:\$"}m
+ap{\$_+20,\$_,\$_+10}\$_[0]=~/./g}}
-- edit: Some explanations about 1005,924745596,341831533
Re: Golf: Seven segment display
by jffry (Hermit) on Jan 23, 2012 at 23:22 UTC

The only problem is that this is not "9"

``` _
|_|
_|

This is:

``` _
|_|
|

Otherwise, the old trick of "59009" upside down doesn't work anymore.

```sub w{for\$;(1005,924745596,341831021){say map{\$;>>\$_&1?/../?'|':_:\$"}m
+ap{\$_+20,\$_,\$_+10}\$_[0]=~/./g}}
w("59009");
output:
``` _  _  _  _  _
|_ |_|| || ||_|
_|  ||_||_|  |

/me flips laptop upside down, laughs like Beavis & Butthead.

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://948530]
Approved by marto
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-24 17:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found