Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Digit Density

by japhy (Canon)
on Dec 27, 2001 at 20:58 UTC ( [id://134640]=note: print w/replies, xml ) Need Help??


in reply to Digit Density

$_=join'',<>; @p=(0)x10; $p[$&]++for/\d/g;
The rest is up to you. I'm just golfing the actual tallying.

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: Re: Digit Density
by termix (Beadle) on Dec 27, 2001 at 21:40 UTC

    Shoot. I am missing something here. I tried your code. It loops the right number of times, but it seems to only see the last character (the first match in a greedy match). So an input of '12345' looks like '55555'.

    To test I tried

    $x="12345"; for ($x=~ /./g) { print $&; } print "\n";

    but this gives me "55555" again. I notice, I should be using a while and I try:

    $x="12345"; while ($x=~ /./g) { print $&; } print "\n";

    which works. So I changed your code to use a while loop also and it works.

    -- termix

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://134640]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-18 22:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found