Topological Sort

Score: 157.51 (pass)

Movin' on up to the back of the pack! Now I need to find another new algorithm!Got any suggestions? Damn those time-wasting hashes! They were way too much fun! Great Hole Rick & company!

#!perl -lan
@u{@F}=@_=(@_,$_)}{@u=keys%u;while(!@g&(++$h<1E4||die$h)){for(@_){@c{@u}=0..@u;@g=($x,$y)=@c{+split};if($x>$y){@u[@g]=@u[$y,$x];@g=();last}}}print for@u

Score: 239.51 (pass)

That's all I have with hashes! This will give Kristen a moving target.

#!perl -lna
z($~,($^,$~)=@F);map{for$^(k($_)){z($_,$^,$~)}}k($~);map{for$^(keys%k){$~eq$^&&die$!or&z($_,$_,$^)if$k{$^}{$~}}}k($~)}map{print}k(@p=sort{$c{$a}<=>$c{$b}}keys%k),@p;{sub z{$k{$a=pop}{+pop}||=++$c{$a}if$^ne$_[0]}sub k{keys%{$k{$_[0]}}}

Score: 252.52 (pass)

Can I go back to Beginner now? Do I at least get my choice of wooden spoons? At least I'm under 4A (4 x Alien)!

#!perl -lna
&q($~,($^,$~)=@F);map{for$^(&k($_)){&q($~,$^,$_)}}&k($~);map{for$^(keys%k){$~eq$^&&die$!or&q($^,$_,$_)if$k{$^}{$~}}}&k($~)}@p=sort{$c{$a}<=>$c{$b}}keys%k;print for &k($p[0]),@p;{sub q{$k{$a=$_[0]}{$_[1]}||=++$c{$a}if$^ne pop}sub k{keys%{$k{+pop}}}

Score: 289.49 (pass)

Before I do the fun part, does this pass? I tries hashes, regex and splice ... now swapping. Where am I supposed to find that magic algo?

#!perl -l
while(<>){
chomp;
push(@l,$_);
}
for(@l){($s,$t)=split;$u{$s}=$u{$t}=1}
@u=keys%u;
$g=1;
while($g&&(++$h<50*@l||die$h)){
for(@l){
$g=0;
($j,$k)=split;
$x=z($j)-1;
$y=z($k)-1;
if($x>$y){@u[$x,$y]=@u[$y,$x];$g=1;last}
}
}
print for@u;
sub z {$c=0;for(@u){if($_[0] eq$u[$c++]){return$c}}0}