Skip to content

Instantly share code, notes, and snippets.

@grondilu
Created August 16, 2013 16:16
Show Gist options
  • Save grondilu/6251288 to your computer and use it in GitHub Desktop.
Save grondilu/6251288 to your computer and use it in GitHub Desktop.
sub longest_increasing_subsequence(@d) {
my @l = [[].item];
for ^@d -> $i {
@l.push: [ max(:by(*.elems), grep { .[*-1] < @d[$i] }, @l[0..$i]).list, @d[$i] ].item;
}
return max :by(*.elems), @l;
}
say .perl given longest_increasing_subsequence <0 8 4 12 2 10 6 14 1 9 5 13 3 11 7 15>».Int;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment