#! perl -slw use strict; use 5.10.0; printf "%s", scalar ; my @points = map[ split ' ', $_ ], ; my @modified; push @modified, shift @points; # Kickstart while ( @points ) { my $cmp = ($points[0][0] <=> $modified[-1][0])*($points[0][1] > $modified[-1][1]); if ($cmp == 1) { push @modified, shift @points; } elsif ($cmp == -1) { shift @points; } else { pop @modified; } } #### while ( @points ) { if (($points[0][0] > $modified[-1][0])^($points[0][1] < $modified[-1][1])) { push @modified, shift @points; } else { shift @points; pop @modified; } } #### while ( @points ) { if (($points[0][0]-$modified[-1][0])/($points[0][1]-$modified[-1][1]) > 0) { push @modified, shift @points; } else { # Retrograde! my @retro = (pop @modified, shift @points); push @retro, shift @points while ($retro[-1][0]-$points[0][0])/($retro[-1][1]-$points[0][1]) < 0; shift @points while ($retro[0][0]-$points[0][0])/($retro[0][1]-$points[0][1]) < 0; pop @modified while ($retro[-1][0]-$modified[-1][0])/($retro[-1][1]-$modified[-1][1]) < 0; push @modified, [0.5*($retro[@retro/2-.5][0] + $retro[@retro/2][0]), 0.5*($retro[@retro/2-.5][1] + $retro[@retro/2][1]), ] } }