#!/usr/bin/perl
use strict; use warnings;
use List::Util qw( min );
use Statistics::Descriptive;
my $stat = Statistics::Descriptive::Full->new;
my @long = (100, 200, 210, 300, 350, 400, 401, 402, 403, 404, 405, 406);
my @short = (3, 6, 120, 190, 208, 210, 300, 350);
for my $x ( @short ) {
$stat->add_data(find_dist($x, @long));
}
my $freq = $stat->frequency_distribution_ref([0, 2, 10, 20, 94, 97]);
for my $bin ( sort { $a <=> $b } keys %$freq ) {
print "$bin: $freq->{$bin}
";
}
sub find_dist {
my ($x, $v) = @_;
return min map abs($x - $_), @$v;
}
Comments
Leave a comment