Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use feature 'say';
- sub dist {
- my ($x1, $y1, $x2, $y2) = @_;
- return sqrt(($x1 - $x2) * ($x1 - $x2) + ($y1 - $y2) * ($y1 - $y2));
- }
- my $data = [];
- my $result = [];
- while (<>) {
- chomp;
- my @d = split;
- push @$data, \@d;
- }
- my $size = scalar @$data;
- for (my $i = 0; $i < $size; $i++) {
- for (my $j = $i + 1; $j < $size; $j++) {
- my $r = [$data->[$i][0], $data->[$i][1], $data->[$j][0], $data->[$j][1]];
- push @$r, dist @$r;
- push @$result, $r;
- }
- }
- @$result = sort { $a->[4] <=> $b->[4] } @$result;
- foreach my $r (@$result) {
- say join "\t", @$r;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement