Topological Sort

Score: 75.48 (fail)

just a little tweaking.

#!perl -lan
$s=~s/\Q$F[1]\E |$/$_ /}{$s{$_}++&&die,print for$s=~/(\S+)(?: +\1)* /g

Score: 75.50 (fail)

#!perl -lan
$s=~s/ \Q$F[1]\E |$/ $_ /}{print,$s{$_}++&&&;for$s=~/(\S+)(?: +\1)* /g

Score: 76.58 (fail)

Wow! I can't believe myself. Beating Ton "The Alien" Hospel? Who'd have thunk? Let's see how long it lasts.

#!perl -lan
$x=~s/\Q$F[1]\E |$/$_ /}{map{$h{$_}++&¨print}$x=~/(\S+)(?: +\1)* /g

Score: 77.48 (fail)

This passes the new test program (v1.4) at the cost of two strokes :-( I am surprised that no one beat me to punch yet. I guess I'll enjoy the lead while I can.

#!perl -lan
$s=~s/ \Q$F[1]\E |$/ $_ /}{$s{$_}++&&die,print for$s=~/(\S+)(?: +\1)* /g

Score: 93.56 (fail)

#!perl -lan
$x=~s/\Q$F[1]\E |$/$_ /}{$x=~s/(\S+)( +\1)+ /$1 /g;map{$h{$_}++&¨print}@x=$x=~/\S+/g

Score: 111.54 (fail)

#!perl -lan
$x=~s/ \Q$F[1]\E |$/ $_ /}{$x=~s/(\S+)( +\1)+ /$1 /g;map$h{$_}++&&die,@x=$x=~/\S+/g;map{$s{$_}++||print}@x

Score: 134.49 (fail)

#!perl -lan
$x=~s/ \Q$F[1]\E |$/ $_ /}{$x=~s/(\S+)( +\1)+ /$1 /g;map{die if $h{$_};$h{$_}++}@x=$x=~/\S+/g;map{print unless $s{$_};$s{$_}++}@x

Score: 159.51 (pass)

#!perl -lan
push@{$h{$F[0]}},$F[1];$h{$F[1]}||=[]}{sub d{my($w,$x)=@_;$c{$w}||=1+do{map{$d++>$.&&&,,$x+=d($_)if$_ ne$w}@{$h{$w}};$x}}map{print}sort{d($b)<=>d$a}keys%h

Score: 160.49 (pass)

just 100 more than The Alien :-)

#!perl -lan
push@{$h{$F[0]}},$F[1];$h{$F[1]}||=[]}{sub d{my$w=pop;my$x=1;$c{$w}||=do{map{$d++>$.&&&,,$x+=d($_)if$_ ne$w}@{$h{$w}};$x}}map{print}sort{d($b)<=>d$a}keys%h

Score: 165.51 (fail)

It passes the test program but takes more than 6 minutes my Duron 600MHz box. Will it get me out of the sandtrap (and barely onto the board)?

#!perl -lan
$i{$_}++||push@{$h{$F[1]}},$F[0];$h{$F[0]}||=[]}{sub d{my($w,$d,$x)=@_;map{$d>$.&¨$x+=1+d($_,++$d)if$_ ne$w}@{$h{$w}};$x}map{print}sort{d($a)<=>d($b)}keys%h

Score: 178.52 (pass)

I refuse to end this on sandtrap. This one's longer but should zip through the tests.

#!perl -lan
$i{$_}++||push@{$h{$F[1]}},$F[0];$h{$F[0]}||=[]}{sub d{my($w,$d,$x)=@_;$c{$w}||=do{map{$d>$.&&die,$x+=1+d($_,++$d)if$_ ne$w}@{$h{$w}};$x}}map{print}sort{d($a)<=>d($b)}keys%h