Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Golf: Buying with exact change

by dragonchild (Archbishop)
on Feb 22, 2005 at 17:52 UTC ( [id://433424]=note: print w/replies, xml ) Need Help??


in reply to Re: Golf: Buying with exact change
in thread Golf: Buying with exact change

I'm down to 111 characters at Re^2: Golf: Buying with exact change using Anonymonk's non-regex solution. I think that with the addition of a few characters, you might be able to remove the 999 restriction on the regex solution.

Update: Melding our solutions gives a 79 character solution that doesn't have the 999 restriction.
$"="}|1{";$r=qr/^(1{@_})+$/;for($t=$s=0;$t-$s<$_[0];(1x++$t)=~/$r/ or$ +s=$t){}$s

Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Replies are listed 'Best First'.
Re^3: Golf: Buying with exact change
by blokhead (Monsignor) on Feb 22, 2005 at 18:16 UTC
    Here's a solution that doesn't have the arbitrary restriction on the solution size, although since it uses the same regex trick as above, the inputs must still be <32k. It's 75 characters:

    ($",$n,$_)="}|1{";while($n++<$_[-1]){$_.=1;/^(1{@_})*$/ or$n=0}length()-pop

    But the non-regex ideas are interesting to me, as I wasn't sure it was easily possible without the regex logic.

    blokhead

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-19 13:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found