just a little tweaking.
#!perl -lan
$s=~s/\Q$F[1]\E |$/$_ /}{$s{$_}++&&die,print for$s=~/(\S+)(?: +\1)* /g
|
#!perl -lan
$s=~s/ \Q$F[1]\E |$/ $_ /}{print,$s{$_}++&&&;for$s=~/(\S+)(?: +\1)* /g
|
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
|
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
|
#!perl -lan
$x=~s/\Q$F[1]\E |$/$_ /}{$x=~s/(\S+)( +\1)+ /$1 /g;map{$h{$_}++&¨print}@x=$x=~/\S+/g
|
#!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
|
#!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
|
#!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
|
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
|
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
|
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
|