gilthoniel has asked for the wisdom of the Perl Monks concerning the following question:
I have an array of numbers (2 6 5 7 4 3 9) and am trying to find the longest increasing subset (2 6 7 9) from these numbers. I'm using algorithm::combinatorics to find combinations of these numbers starting from the largest and essentially trying to keep the first combination that has all the numbers in ascending numerical order, but for some reason it's not stopping where I expect it to and giving the answer (2 6 7 4 3)
until(@answer) { my $iter = combinations(\@array2,$Fcount); while (my $p = $iter->next) { until(@answer) { my @forward = @$p; my $number1 = 1; my $number2 = 2; if ($forward[$number1] < $forward[$number2]) { $number1++; $number2++; } else { last; } if ($number2 = (scalar(@forward)+1)) { push @answer, @$p; print "@$p\n"; last; } } } $Fcount = ($Fcount - 1); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Longest Increasing Subset
by tybalt89 (Monsignor) on Oct 19, 2016 at 21:48 UTC | |
by gilthoniel (Novice) on Oct 20, 2016 at 15:55 UTC | |
by tybalt89 (Monsignor) on Oct 20, 2016 at 18:03 UTC | |
by BrowserUk (Patriarch) on Oct 20, 2016 at 19:58 UTC | |
by Dallaylaen (Chaplain) on Oct 24, 2016 at 08:49 UTC | |
| |
by pryrt (Abbot) on Oct 20, 2016 at 18:35 UTC | |
|
Re: Longest Increasing Subset
by GrandFather (Saint) on Oct 20, 2016 at 02:43 UTC | |
|
Re: Longest Increasing Subset
by pryrt (Abbot) on Oct 19, 2016 at 22:23 UTC | |
|
Re: Longest Increasing Subset
by johngg (Canon) on Oct 19, 2016 at 21:35 UTC | |
|
Re: Longest Increasing Subset
by Dallaylaen (Chaplain) on Oct 23, 2016 at 23:01 UTC | |
|
Re: Longest Increasing Subset
by BrowserUk (Patriarch) on Oct 19, 2016 at 21:30 UTC |