Your skill will accomplishwhat the force of many cannot PerlMonks

### Comment on

 Need Help??
Here's a solution with no limits (beyond the memory used by memoize). It answers largest(1000, 1001, 1002, 1003, 1004, 1005) in 19 secs (the answer is 199,999 by the way). If you turn off memoize it takes much longer, although probably just days rather than centuries, It's based on a previous perlmonks challenge: How to generate restricted partitions of an integer.

It's definitely not golf! Is there a golfish answer that runs in similar time?

```#! /usr/bin/perl

use strict;
use warnings;

my @all;

use Memoize;

memoize('breakup');

print largest(@ARGV)."\n";

sub largest
{
my \$small = shift;
my %need;

@all = reverse @_;

my \$highest = 0;

for my \$m_target (1..(\$small-1))
{
# find the smallest number (\$target) which can be made from the in
+put
# numbers and which gives remainder \$m_target when divided by \$sma
+ll.

my \$target = \$m_target;
while (\$target += \$small)
{
if (0) # change to 1 to see details
{
my @b = breakup(\$target, 0);
nice(\$target, @b);
}
last if breakup(\$target, 0);
}
\$target -= \$small;
print  "\$target == \$m_target (mod \$small)\n";
\$highest = \$target if \$highest < \$target;
}
return \$highest;
}

sub nice
{
my \$target = shift;
print "---------------\n\ntarget = \$target\n";
foreach my \$sol (@_)
{
print join(", ", @\$sol)."\n";
}
}

sub breakup
{
my (\$target, \$sub) = @_;
#  \$count++;

my \$cur = \$all[\$sub];

my @solns;
if (\$target == \$cur)
{
push(@solns, [\$cur]);
}

if (\$target >= \$cur)
{
push(@solns, map {[\$cur, @\$_]} (breakup(\$target - \$cur, \$sub)));
}

push(@solns, breakup(\$target, \$sub + 1)) unless (\$sub == \$#all);

return @solns;
}

I'm going to bed now so I won't explain in detail. Hopefully someone will have posted a more golfish solution by the time I get to work tomorrow and I won't have to bother.

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
 [msh210]: I think I just found a lie in perldoc. [msh210]: warn: "If the last element of LIST does not end in a newline, it appends the same file/line number text as die does." [msh210]: perl -e'warn "test\$/", "" ' [msh210]: doesn't append anything. [msh210]: It should say "If the last nonempty element of LIST" or "If the string thus to be printed does not end in a newline""

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2017-04-24 12:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
I'm a fool:

Results (439 votes). Check out past polls.