Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Golf: Buying with exact change

by kvale (Monsignor)
on Feb 22, 2005 at 01:43 UTC ( #433224=note: print w/ replies, xml ) Need Help??


in reply to Golf: Buying with exact change

Fun problem. Here is a solution in 72 characters with a bound of 1000:

sub largest {my$r;$r.='('.5x$_.')*'for@_;for($i=1000;;$i--){return$i if(5x$i)!~/^$r$/}}

-Mark


Comment on Re: Golf: Buying with exact change
Replies are listed 'Best First'.
Re^2: Golf: Buying with exact change
by !1 (Hermit) on Feb 22, 2005 at 02:08 UTC

    64

    sub largest { # 345678 1 2345678 2 2345678 3 2345678 4 2345678 5 2345678 6 234 my$r;$r.='('.5x$_.')*'for@_;for($i=1000;(5x$i)=~/^$r$/;$i--){}$i }
      59

      sub largest {
      # 345678 1 2345678 2 2345678 3 2345678 4 2345678 5 23456789
      @r=map'('.5x$_.')*',@_;for($=**=2;(5x$=)=~/^@r$/x;$=--){}$=
      }
      

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2015-07-29 02:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls