Fun, kinda silly, and doesn't actually work on your trial set. Failures happen around points with large deviations from the smoothed concept.
my @also = sort {$a->[0] <=> $b->[0]} @points;
for my $i (reverse 0 .. $#points) {
splice @also, $i, 1 if $points[$i] ne $also[$i];
}
More generally, I feel like there is a merge-sort-like solution in there somewhere, but can't quite seem to distill it in my brain. Not that it would be practical, since push-pop is already O(N), but that's not the point, right?
Streaming buffer w/ STDIN/STDOUT:
my $frame = 10;
my @buffer;
$, = ' ';
$\ = "\n";
while (<>) {
my @row = split;
if (@buffer and ($buffer[-1][0] < $row[0]) ^ ($buffer[-1][1] < $ro
+w[1]) ) {
pop @buffer;
} else {
print @{shift @buffer} if $frame < push @buffer, \@row;
}
}
print @$_ for @buffer
Note the ridiculous micro-optimization for comparison.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
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.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, 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?
See Writeup Formatting Tips and other pages linked from there for more info.