Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: How would you code this?

by BrowserUk (Patriarch)
on Apr 07, 2016 at 15:01 UTC ( [id://1159821]=note: print w/replies, xml ) Need Help??


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

I concur that this produces the same output. My main objections to are: a) it uses more decision points to achieve it; b) it messes with the input array (curable).

Thanks for your input.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^3: How would you code this?
by Marshall (Canon) on Apr 07, 2016 at 20:47 UTC
    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://1159821]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2024-04-18 15:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found