use strict; use warnings; use Array::Transpose; my @students = ( [qw(cap shortsleeve jeans leather flipflop)], [qw(beenie longsleeve shorts cloth highheel)], [qw(cap tanktop shorts rope flat)], [qw(beenie longsleeve shorts cloth flipflop)] ); my %compares; for my $x (0..$#students) { for my $y ($x+1..$#students) { $compares{$x.",".$y} = 1 } } my $categories = transpose([$students[0],$students[1],$students[2],$students[3]]); my %diffs; for my $category (0..$#{$categories}) { my %type; my @kidcompare; for my $type (0..$#{$categories->[$category]}) { if (exists($type{$categories->[$category]->[$type]})) { push @kidcompare, $type{$categories->[$category]->[$type]} . "," . $type; } else { $type{$categories->[$category]->[$type]} = $type } } for (@kidcompare) { $diffs{$_}++ } } my $winner = 4; for (sort(keys(%compares))) { if (exists($diffs{$_})) { if ($diffs{$_} < $winner) { $winner = $diffs{$_} } } else { print "Short Winner $_\n"; exit } } print "Winner $winner\n";