in reply to How would you code this?
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?my @also = sort {$a->[0] <=> $b->[0]} @points; for my $i (reverse 0 .. $#points) { splice @also, $i, 1 if $points[$i] ne $also[$i]; }
Streaming buffer w/ STDIN/STDOUT:
Note the ridiculous micro-optimization for comparison.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
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|
|---|