#!/usr/bin/perl
 
use strict;
use warnings;
      
my $file = $ARGV[0];
my @name1 =();
my @name2 =();
my @score =();
my $i =0;
open(my $data, '<', $file) or die "Could not open '$file' $!\n";
 
while (my $line = <$data>) {

$line =~ /(.*)\t(.*)\t(\d+)/; 
$name1[$i] = $1;
$name2[$i] = $2;
$score[$i] = $3;
$i++;
}
my $schnitt1 = "";
my $schnitt2 = "";
my $infscore =1000;
my $stoppen = "F";
my $index = 0;
my $length =0;
my $arraylength = @score;
my $counter1 =0;
my $counter2 =0;
#open(LOG, ">".$file.".done");     
#select LOG;
while($stoppen eq "F")
{
    $infscore=1000;
    $length =0;
    $arraylength = @score;

    while($length < $arraylength)
    {
	if($score[$length] <= $infscore)
	{
	    $infscore = $score[$length];
	    $index = $length;
	}
	$length++;
    }
    $length =0;
    $schnitt1 = $name1[$index];
    $schnitt2 = $name2[$index];
    splice(@name1, $index,1);
    splice(@name2, $index,1);
    splice(@score, $index,1);
    $arraylength = @score;
    $counter1 =0;
    $counter2 =0;
    
    while($length < $arraylength)
    { 
	if($name1[$length] eq $schnitt1 || $name2[$length] eq $schnitt1)
	{
	    $counter1++;
	}
	if($name1[$length] eq $schnitt2 || $name2[$length] eq $schnitt2)
	{
	    $counter2++;
	}
	$length++;
    }

 #   print $schnitt1."\t".$counter1."\t".$schnitt2."\t".$counter2."\n";
      	    	
    if($counter1 == 0)
    {
	print $file."\tDas faule Ei ist ".$schnitt1."\n";

	$stoppen = "T";
	
    }
    if($counter2 == 0)
    {
	print $file."\tDas faule Ei ist ".$schnitt2."\n";

	$stoppen = "T";
    }


}
#close(LOG);
close($data);
