Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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?
[marto]: good morning all
[Corion]: Hi marto ;)
[Corion]: I hope you're well ;)
[marto]: running late today, get to work and people are just sitting around. "can't delete file, quota exceeded"
[Corion]: marto: Oy :-/
[Corion]: Ah, it's only "quota exceeded", not "filesystem full", so it's "merely" an administrative act to up the FS quota resp. inode quota
[Corion]: I've been on databases where I couldn't drop a table or delete rows because the DB was full. Not so much fun...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2017-01-24 09:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (203 votes). Check out past polls.