Created
March 30, 2012 14:52
-
-
Save jimregan/2252068 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use warnings; | |
use strict; | |
sub distance { | |
my $first = shift; | |
my $second = shift; | |
my @weight = qw(8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 16 16 16 16 16 16 16 16 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32); | |
my $dist = 0.0; | |
my $dif; | |
for my $i (0..47) { | |
$dif = $first->[$i] - $second->[$i]; | |
$dist += $weight[$i] * $dif * $dif; | |
} | |
return $dist; | |
} | |
sub distpercent { | |
my $distance = shift; | |
my $maxdist = 98406; | |
return (($maxdist - $distance) * 100) / $maxdist; | |
} | |
my @list; | |
while(<>) { | |
my ($name, $desc) = split(/;/,$_); | |
my $rec = {}; | |
$rec->{'name'} = $name; | |
$rec->{'desc'} = $desc; | |
push @list, $rec; | |
} | |
for my $f (@list) { | |
for my $s (@list) { | |
next if ($f->{'name'} eq $s->{'name'}); | |
my @a = split(/ /, $f->{'desc'}); | |
my @b = split(/ /, $s->{'desc'}); | |
my $dis = distpercent(distance(\@a, \@b)); | |
next if ($dis < 80.0); | |
print "$f->{'name'}; $s->{'name'}; $dis\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment