Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

The greedy change-making problem using regexes

by blokhead (Monsignor)
on Mar 10, 2005 at 00:59 UTC ( [id://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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-19 16:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found