#!/usr/bin/perl
use File::Copy 'cp';

for my $prog (@ARGV) {
  print STDERR '.';
  unlink <mismatches/$prog/*>;
  my $score = 0;
 OUTPUT:
  for my $output (<outputs/$prog/*>) {
    (my $expected = $output) =~ s|.*/||;
    my @x = <standard/$expected-*.*>;
    unless (@x) {
      die "expected=$expected produced no matches!\n";
    }
    for my $x (@x) {
      if (system("cmp -s $output $x") == 0) { # matches
        my ($points) = ($x =~ /-(\d+)\./);
        $score += $points;
        next OUTPUT;
      }
    }
    mkdir "mismatches/$prog", 0777;
    cp($output, "mismatches/$prog/$expected") or die $!;
  }
  $score{$prog} = $score;
}
print STDERR "\n";

for my $prog (sort {$score{$b} <=> $score{$a} || $a cmp $b} keys %score) {
  printf "%12s: %3d\n", $prog, $score{$prog};
}
