Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: knapsack problem solved by regex

by blokhead (Monsignor)
on Mar 14, 2010 at 16:02 UTC ( #828586=note: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my $max_weight = 10;
    my %items      = (      # value, weight: positive integers
      'a'  => { v => 1, w => 2 },
      'b'  => { v => 11,  w => 9 },
    );
    
  2. or download this
               first half           second half
               $1  $2
    attempt 1: v   vvvvvvvvvvv  --> ww + wwwwwwwww = 11, not enough w's!
    backtrack
    attempt 2: v   <empty>      --> ww = 2, enough w's for this, so accept
    +ed
    
  3. or download this
    # used to be:
    # my $re = sprintf "%s0\n(?=\n%s)\n", $left, $right;
    ...
    my $re = sprintf qq[%s0\n(?{ print "trying " . Dumper \\%%+})\n(?=\n%s
    +)\n],
        $left, $right;
    print $re;
    
  4. or download this
    STRING:
    vvvvvvvvvvvv0wwwwwwwwww
    ...
              'a' => '',
              'b' => 'vvvvvvvvvvv'
            };
    
  5. or download this
    STRING:
    vvvvvvvvvvvv0wwwwwwwwww
    ...
              'a' => '',
              'b' => 'vvvvvvvvvvv'
            };
    
  6. or download this
    ^
    (?<a>(?:v)?)
    (?<b>(?:vvvvvvvvvvv)?)
    v*
    0
    
  7. or download this
    (?<a>(?:v)?)
    (?<b>(?:vvvvvvvvvvv)?)
    0
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2014-11-28 02:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (192 votes), past polls