Topological Sort

Score: 108.55 (pass)

Who had thought that even "die" could be made shorter ;-)

#!perl -lap
@t{@q{@F}=@F}.=" $F[0] "x!/^\Q$F[1] /}for(keys%q){1/(($_)=grep!$t{$_},%q);$t{$w=$_}+=map{s/ \Q$w //g}%t

Score: 115.54 (pass)

I tried using grep a few times already. But suddenly it gave a gain %)

#!perl -lap
@t{@F}.=" $F[0] "if$F[0]ne$F[1];@q{@F}=@F}for(keys%q){(($_)=grep!$t{$_},%q)||die;$t{$,=$_}+=map{s/ \Q$, //g}%t

Score: 122.51 (pass)

My last solution is actually invalid according to the rules (see seperate mail for a test case). Fix it.

#!perl -lan
@t{@F}.=" $F[0] "if$F[0]ne$F[1];@q{@F}=@F}for(keys%q){map$t{$_}||do{$t{$,=$_}+=print;map{s/ \Q$, //g}%t;next},%q;die;

Score: 124.53 (fail)

My last submission got rejected. Have to try again...

#!perl -lan
@t{@F}.=" $F[0] "if$F[0]ne$F[1];@q{@F}=@F}for(keys%q){$t{$_}||$,or$t{$,=$_}+=print for%q;$,=$,?!map{s/ \Q$, //g}%t:die;

Score: 127.54 (fail)

Creative use of ?: and loosing a space shoul put me in the top 10 for now. - Time for bed!

#!perl -lan
$t{$F[1]}.=" $F[0] "if$F[0]ne$F[1];@q{@F}=@F}for(keys%q){$t{$_}||$,or$t{$,=$_}+=print for%q;$,=$,?!map{s/ \Q$, //g}%t:die;

Score: 131.52 (fail)

Use that nice 5.6.1 feature to modify hash values

#!perl -lan
$t{$F[1]}.=" $F[0] "if$F[0]ne$F[1];@q{@F}=@F}for(keys%q){$t{$_}||$d or$t{$d=$_}+=print for%q;$d||die;map{s/ \Q$d //g}%t;$d="";

Score: 137.54 (fail)

Yet another way to write the if/for.

#!perl -lan
$t{$F[1]}.=" $F[0] "if$F[0]ne$F[1];@q{@F}=@F}for(keys%q){$t{$_}||$d||($t{$d=$_}+=print)for%q;$d||die;map{$t{$_}=~s/ $d //g}%t;$d="";

Score: 139.54 (fail)

A new testcase steals two more characters from me.

#!perl -lan
$t{$F[1]}.=" $F[0] "if$F[0]ne$F[1];@q{@F}=@F}for(keys%q){$t{$_}||$d||($t{$d=$_}+=print)for%q;$d||die;map{$t{$_}=~s/ \Q$d //g}%t;$d="";

Score: 142.51 (fail)

Reformatting the for/if gives a few more chars

#!perl -lan
$t{$F[1]}.=" $F[0] "if$F[0]ne$F[1];@q{@F}=@F}for(keys%q){$t{$_}||($t{$d=$_}+=print)and last for%q;$d||die;map{$t{$_}=~s/ $d //g}%t;$d="";

Score: 145.52 (fail)

New try: we store strings inside those hashes. (So much work for only three points gain)

#!perl -lan
$t{$F[1]}.=" $F[0] "if$F[0]ne$F[1];@q{@F}=@F}for(keys%q){for(%q){if(!$t{$_}){print;$t{$d=$_}=1;last}}$d||die;map{$t{$_}=~s/ $d //g}%t;$d="";

Score: 148.49 (fail)

Some more strokes shaved with s/values//;

#!perl -lan
$t{$F[1]}{$F[0]}=1if$F[0]ne$F[1];$t{$F[0]}{a}}for(keys%t){for(keys%t){!%{$t{$_}}&&print&&delete$t{$d=$_}&&last}map{delete$$_{$d||die}}%t;$d="";

Score: 154.47 (fail)

I had completely forgotten about 'values'

#!perl -lan
$t{$F[1]}{$F[0]}=1if$F[0]ne$F[1];$t{$F[0]}{a}}for(keys%t){for(keys%t){!%{$t{$_}}&&print&&delete$t{$d=$_}&&last}map{delete$$_{$d||die}}values%t;$d="";

Score: 156.47 (fail)

loose some "if". &&,|| and "and" are shorter

#!perl -lan
$F[0]ne$F[1]and$t{$F[1]}{$F[0]}=1;$t{$F[0]}{a}}for(keys%t){for(keys%t){!%{$t{$_}}&&print&&delete$t{$d=$_}&&last}map{delete$t{$_}{$d||die}}keys%t;$d="";

Score: 164.47 (fail)

A few more easy optimisations: for->map, omit 'scalar' or 'keys' here and there.

#!perl -lan
$t{$F[1]}{$F[0]}=1if($F[0]ne$F[1]);$t{$F[0]}{a}}for(keys%t){for(keys%t){if(!%{$t{$_}}){print;delete$t{$d=$_};last}}die if!$d;map{delete$t{$_}{$d}}keys%t;$d="";

Score: 189.44 (fail)

Try my file obfuscator for obvious gains in whitespace.

#!perl -lan
$t{$F[1]}{$F[0]}=1if($F[0]ne$F[1]);$t{$F[0]}{a}}for(1..scalar keys%t){for(keys%t){if(!scalar keys%{$t{$_}}){print;delete$t{$_};$d=$_;last}}die if!$d;for(keys%t){delete$t{$_}{$d}}$d="";

Score: 243.50 (fail)

Try the file upload box so formatting is kept sane.

#!perl -lan

	$t{$F[1]}{$F[0]}=1 if($F[0] ne$F[1]);
	$t{$F[0]}{a};
}

for(1..scalar keys%t){
	for(keys %t){
		if(!scalar keys%{$t{$_}}){
			print;
			delete $t{$_};
			$d=$_;
			last;
		};
	};
	die if!$d;
	for(keys %t){
		delete $t{$_}{$d};
	};
	$d="";

Score: 410.54 (fail)

My first working solution *uff*

#!perl -lan

$t{$F[1]}{$F[0]}=1 if($F[0] ne$F[1]);;
$t{$F[0]}{""};
}

{

        for(1..scalar keys%t){
for$a(keys %t){
#       print "Looking at $a: ",scalar keys(%{$t{$a}});
        if(!scalar keys%{$t{$a}}){
                print $a;
                delete $t{$a};
                $d=$a;
                last;
        };
};
die if!$d;
for$a(keys %t){
#       print "Del $a,$d";
        delete $t{$a}{$d};
};
$d="";
};