Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

The greedy change-making problem using regexes

by blokhead (Monsignor)
on Mar 10, 2005 at 00:59 UTC ( #438118=perlmeditation: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    use re 'eval';
    use Test::More 'no_plan';
    ...
    is greedy_is_optimal(1,5,10,25), 1;
    is greedy_is_optimal(1,6,10,25), 0;
    is greedy_is_optimal(1,5,7),     0;
    
  2. or download this
        ^ ( 1{7} (?{ $^R+1 }) )* (?!1{7})
          ( 1{5} (?{ $^R+1 }) )* (?!1{5})
    ...
          (?{ $x = $^R }) x
      | ^ ( (1{1}|1{5}|1{7}) (?{ $^R+1 }) )*
          (?(?{ $^R < $x }) $ | x )
    
  3. or download this
     ^ (1{7})* (?!1{7}) (1{5})* (?!1{5}) (1{1})* (?!1{1})
    
  4. or download this
    (?{ $x = $^R }) x
    
  5. or download this
     ^ ( (1{1}|1{5}|1{7}) (?{ $^R+1 }) )* 
       (?(?{ $^R < $x }) $ | x )
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://438118]
Approved by Tanktalus
Front-paged by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2014-09-22 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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











    Results (185 votes), past polls