in reply to Tic Tac Chop

Well, I did my best, but I could only squeeze it down to 177 characters long, assuming no newlines. I think it works. $"='ox'x5,$_="1 2 3\n4 5 6\n7 8 9 ";{$^=chop$";print"$_$^>"; {<>=~/^(\d)$/&&s/$1/$^/||$.--&&redo}/^($^.){3}|($^.{5}){2}$^ |($^.{7}){2}$^|^.(...$^){3}/sm|8<$.||redo}y/0-9/-/;print I must congratulate turnstep, it is quite exquisite. I did steal some stuff from Adam here, I must admit. I think I'm going to frame that and put it on my wall. I wouldn't be surprised if someone could still chop a character or two off, though.

Replies are listed 'Best First'.
Re: RE: Tic Tac Chop
by japhy (Canon) on Dec 06, 2000 at 08:29 UTC
    Mine is a hair shorter. 167 chars with newlines, 163 without them, and none of them are needed. The only whitespace is in the grid string.
    $_="1 2 3\n4 5 6\n7 8 9\n";$m="XOXOXOXOX"; {print;<>=~/^\d$/until$&&&s/$&/$p=chop$m/e; /^($p.){3}|($p.{5}){2}$p|^.(...$p){3}|($p.{7}){2}$p/ms||$m&&redo} y/0-9/-/,print


    japhy -- Perl and Regex Hacker
      you can trim a couple more off the $m assignment to:
      $_="1 2 3\n4 5 6\n7 8 9\n";$m="XO"x5; {print;<>=~/^\d$/until$&&&s/$&/$p=chop$m/e; /^($p.){3}|($p.{5}){2}$p|^.(...$p){3}|($p{7}){2}$p/ms||$m&&redo} y/0-9/-/,print
      I am still trying to grok a way to trim that regex down. a definite ++
        No, you can't, since $m's length is used to stop the looping of the program. It has to have length of 9.
        chop($m="XO"x5); # 16 $m="XOXOXOXOX"; # 15 $x="X"."OX"x4; # 14
        There's a one character optimization. Oh, and I left out a . from my code (and thus, it shows above in yours) at the $p{7}. It should be $p.{7}.

        japhy -- Perl and Regex Hacker