Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re:{2} (Golf) Giving Change

by jeroenes (Priest)
on Jun 12, 2001 at 14:54 UTC ( #87765=note: print w/ replies, xml ) Need Help??


in reply to Re: (Golf) Giving Change
in thread (Golf) Giving Change

Nice solution. There is room for improvement, though. No need for return, use that for filtering out empty items:

sub c {($a,$c)=@_;@c=@$c;grep$_,map{$a>$_? &{sub{$a-=$_*($b=int($a/$_));"$b x $_"}}:""} reverse @c}
Char-neutral, but leaving the grep out gains 7 chars.

You don't need the parens after the int, and leave out the spaces around the reverse. Gains you 4 char:

sub c{($a,$c)=@_;@c=@$c;grep$_,map{$a>$_? &{sub{$a-=$_*($b=int$a/$_);"$b x $_"}}:""}reverse@c}

Jeroen
"We are not alone"(FZ)


Comment on Re:{2} (Golf) Giving Change
Select or Download Code
Re: Re:{2} (Golf) Giving Change
by Trimbach (Curate) on Jun 12, 2001 at 15:24 UTC
    Ooooooooo... I like the grep idea. Duh. Can you tell I don't golf much? :-D Spiffy!

    Gary Blackburn
    Trained Killer

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (10)
As of 2014-09-22 15:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (198 votes), past polls