Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: (Golf) Tic Tac Toe

by belg4mit (Prior)
on Jun 07, 2004 at 04:22 UTC ( #361866=note: print w/replies, xml ) Need Help??

in reply to (Golf) Tic Tac Toe

If you relax some of the requirements the code below comes in at 147
$_="123 456 789 147,258,369,159,357"; sub d{/.{12}/s;print$&.($p= $p?0:X);die$_ for@_}d; while(<>=~/\d/&&s/$&/$p/g){ /$p{3}/?d$p:!/\d/ ?d"Tie":d }
The relaxation's are you automatically lose if you try to cheat :-P i.e; given invalid input UPDATE: this can be remdedied with a goto but that brings it up to 153. The output is a little jury-rigged. I use 0 instead of O to allow for some shaving. Also, instead of where you die $p, the loser dies in this game.

UPDATE 2: 144

$_="123 456 789 147,258,369,159,357"; sub d{/.{12}/s;print$&.( $p=$p?0:X);@_&&die@_}d; while(<>=~/\d/&&s/$&/$p/g){ /$p{3}/?d$p:!/\d/?d"Tie":d }

I should mention, I really like the way you use $_. It takes a double-take or two to figure out what's going on but it's rather elegant.

I'm not belgian but I play one on TV.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://361866]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2017-10-18 07:57 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (243 votes). Check out past polls.