Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Sorting geometric coordinates based on priority

by kcott (Archbishop)
on Feb 03, 2017 at 03:13 UTC ( [id://1180921]=note: print w/replies, xml ) Need Help??


in reply to Sorting geometric coordinates based on priority

G'day Ppeoc,

Here's my take on this:

#!/usr/bin/env perl use strict; use warnings; my @rect_x = (3,2,4,0,3,0,4,0,3,2,0,4); my @rect_y = (0,0,0,1,1,0,3,3,3,3,2,2); my @point_x = (0) x @rect_x; my @point_y = (0) x @rect_x; my @sorted = sort { $b->[0] <=> $a->[0] || $a->[1] <=> $b->[1] } map { [ $rect_x[$_], $rect_y[$_], $point_x[$_], $point_y[$_] ] } 0 .. $#rect_x; use Data::Dump; dd \@sorted;

Output:

[ [4, 0, 0, 0], [4, 2, 0, 0], [4, 3, 0, 0], [3, 0, 0, 0], [3, 1, 0, 0], [3, 3, 0, 0], [2, 0, 0, 0], [2, 3, 0, 0], [0, 0, 0, 0], [0, 1, 0, 0], [0, 2, 0, 0], [0, 3, 0, 0], ]

— Ken

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-24 20:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found