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); }
In reply to Longest Increasing Subset by gilthoniel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |