Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^3: How would you code this?

by Marshall (Canon)
on Apr 07, 2016 at 20:47 UTC ( [id://1159838]=note: print w/replies, xml ) Need Help??


in reply to Re^2: How would you code this?
in thread How would you code this?

I made a couple of slight revisions (eliminate the "last" statement and fixed a boundary condition issue at index 0). This still produces the same output.

Appreciated your thanks. I leave "what is better" up to you.

#! perl -slw use strict; printf "%s", scalar <DATA>; my @points = map[ split ' ', $_ ], <DATA>; my $i=0; while ($i < @points-2) #quit when there aren't 2 points left { my ($x1,$y1) = @{$points[$i]}; my ($x2,$y2) = @{$points[$i+1]}; if ( ($y2 - $y1 ) / ( $x2 - $x1 ) < 0 ) { splice @points,$i,2; #remove both points $i--; #backup a point to restart $i=0 if $i<0; #boundary condition at index 0 } else { $i++; } } print join ' ', @$_ for @points;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1159838]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-03-28 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found