You get on stdin 10 strings of length 10, where each character is either space or x, so each line matches /^[ x]{10}\n\z/. Print "1\n" to stdout if there is a path of x's from top to bottom (the path may twist and turn), "0\n" otherwise. (only vertical and horizontal contacts count, NOT diagonal). Nothing should appear on stderr. Multiple paths, dead ends, loops and disconnected pieces are possible.
example input:
x x x x x xxx xx xxx x x x xxx x xxx xxxxx x x xxx xx x xxx xxx xClearly there is at least one path of x's from top to bottom (e.g. the one in red), so the result should be:
1
There is a testprogram provided by Rick Klement.
The challenge runs under the generic perl golf rules.
ton,mtve 55 tybalt89,j. snellman 57 b. chauvet 58 suo 59 dave 60 k. ivey 63 spiff 64 h. pazdziora 75 oozy 85 m. thelen 96 j.tilton 100 juuso 104 Ion 106 c. dolan 131 m. ruderer 133 j. McCrea 145 andys 152 yanick 186 lard 306
ton 55 -lp0 $_=s##s/(\S)(|.{10})(?!\1)\S|$/0$+0/s.$_#eg&/1.*0/ mtve 55 -lp0 $_%=s#.#s/y(.{10})?x|x(.{10})?y|$/y$+y/s;?^.*y?#eg tybalt89 57 -lp0 $_+=s/(\w)(\D{10})?(?!\1)\w|x(.*)$/X$+X/?redo:/^.*X/ j. snellman 57 -lp0 $_+=s/(\w)(\C{10})?(?!\1)\w|^(.*)x/X$+X/?redo:/X.*$/ mtve 57 -lp0 $_=eval's/y(.{10}|)x|x(.{10}|)y|$/y$+y/s*?^.*y?;'x99 b. chauvet 58 -lp0 $_+=s/x(.*)$|(\w)(\D{10})?(?!\2)\w/z$+$2/?redo:/^.*z/ suo 59 -lp0 $_.=$^T;1while s/(\S)(.{10})?(?!\1)\S/y$2y/s;$_+=/^.*y/ tybalt89 59 -lp0 $_=/z.*$/+(s/(\w)(|\D{10})(?!\1)\w|^(.*)x/z$+z/&&redo) tybalt89 59 -lp0 $_.=$^;1while s/(\w)(|.{10})(?!\1)\w/z$+z/s;$_+=/^.*z/ ton 60 -lp0i(|.{9,11}) $_=s/^ /0/m+s/0$^I | $^I0/0$+0/s?do$0:1-/0\n/ dave 60 -lp0i(.{10})? $_+=s/^([^\n]*)x|x$^Iy|y$^Ix/y$+y/s?redo:/y.*$/ suo 61 -lp0 1while s/(y|y\D{10})x|x(\D{10}y|y|.*$)/$1y$2/;$_+=/^.*y/ k.ivey 63 -lp0 1while$_|=1x10,s/x(.{10}|)y|y(.{10}|)x/y$+y/gs;$_=0+/y.*$/ spiff 64 -lp0 s+^+o+while($^T/=2)+s+(\w)(.{10}|)(?!\1)\w+o$2o+s;$_+=/o.*$/ q.huo 67 -lp0 1while s/^(.*)x/$+r/|s/x(.{10})?r|r(.{10})?x/r$+r/s;$_+=/r.*$/ (submitted too late) h.pazdziora 75 -0777p 1while s/ $/k/m|s/(k| )(|.{9,11})(?!\1)[k ]/k${2}k/s;$_=1*!/^k/m.'\n' oozy 85 -p s/x/I/g;$_.=join'',<>;1 while s/x(.{10})?I|I(.{10})?x/I$+I/s;$_=(/I.*\Z/?1:0)."\n"; j.tilton 100 -lp0 sub g{my$h+=pop;$d=~s/^(.{$h})x/$1/s&&map{g($h+$_)}11,1,-1,-11;$s|=$h>119}$d=x x 10 .$_;$_=g juuso 104 -l @p[0]=@m=<>;($d=$p[$_%=10])=~/./,$p[$_]|=$m[$_]&($p[$_-1]|$p[$_+1]|" $d"|$')for 1..999;print$d=~/x/+0 c.dolan 131 -p0 split//,'x'x11\n.$_;do{$_|=$y>9,push@p,$x,$y-1,$x-1,$y,$x+1,$y,$x,$y+1if$_[($y=pop(@p)%999)*11+(+$x=pop@p)]=~s/x//}while@p;s/$/\n/ m.ruderer 133 sub w{my$i=pop;$a[$i]=0;map$a[$I=$i+$_]eq x?abs$I>95?$e=1:w($I):1,1,-1,-11,11}@a=map/./sg,<>;$a[$_]eq x&&w($_)for(0..9);print$e||0,$/ j.McCrea 145 -nl $n++||y/x/0/;$t.=$_}{map{$y=$x=!map{$a[10*++$x-$y]=$_.$/x!$y;$x=!++$y if$x=~0}$t=~/./g;($t=join"",@a)=~s/0x|x0/00/g}0..97;print$t=~/^.*0/?1:0 j.McCrea 303 #!perl -nl @{$p[++$k]}=/./g}{%r=(d,['01drlu'=~/./g],r,['10drul'=~/./g],l,[-1,0,dlur=~/./g],u,[0,-1,rlud=~/./g]);for$x(0..9){$y=$c=0 if 10>$y;1 while 10>$y&&&g&&$c<99}print$y>9|0;sub g{for(@{$r{$l||d}}[2..5]){$c++;($s,$t)=@{$r{$_}};$x+=$s;$y+=$t;$x+1&&$y+1&&${$p[$y]}[$x]=~x?return$l=$_:($x-=$s)&($y-=$t)}0} lard 306 map$a[0][$_]="w",(0..9);push(@a,map[/./g],<>);sub f{($a,$r)=@_;$g=0;for($n=0;$n<10;$n++){if((${$a}[$r][$n]=~x)&&((${$a}[$r][$n+1]=~w)||(${$a}[$r][$n-1]=~w&&$n>0)||(${$a}[$r-1][$n]=~w)||${$a}[$r+1][$n]=~w)){${$a}[$r][$n]="w";$g=1}}$g}$u=$q=1;while($u<11){if($u==0){print"0\n";exit}f(\@a,$u)==1?$u++:$u--;}print"1\n"Post mortem solution:
mtve+ton 54 -lp0 $_%=s#.#s/(\S)(|.{10})(?!\1)\S|$/y$+y/s;?^.*y?#eg