Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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.


Comment on Re: (Golf) Tic Tac Toe
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://361866]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2015-07-30 11:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (271 votes), past polls