Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: (Golf) Tic Tac Toe

by ambrus (Abbot)
on Jun 06, 2004 at 22:08 UTC ( #361818=note: print w/ replies, xml ) Need Help??


in reply to (Golf) Tic Tac Toe

Just an idea. This may or may not help in the golf, but is good to know anyway.

If you take this magic square:

2 9 4 7 5 3 6 1 8
and play tic-tac-toe on it, you have three in a row iff you have three different cells so that the sum of their three numbers is 15.

Source of the idea:

Csákány Béla, Diszkrét matematikai játékok.
1998, Polygon, Szeged
pp. 100-101

Update: changed 1 in 1st row to 2. Thanks to jdhawke and also QM for noticing the typo.

Update: this one does not check for valid moves so it's easy to cheat. Also, it does not detect ties yet.

s;;294 753 618 ;;$f=(OX)x9;{print$_,$u=chop$f;$n=<>-Q;s;$n;$u;e;$$u&1<<15-$n&&die$u.$ +/;$$u|=$$u[0]<<$n;$$u[0]|=1<<$n;redo}


Comment on Re: (Golf) Tic Tac Toe
Select or Download Code
Re^2: (Golf) Tic Tac Toe
by jdhawke (Acolyte) on Jun 06, 2004 at 23:55 UTC
    should that square be:
    2 9 4 7 5 3 6 1 8
    Otherwise the first column and row only sums to 14. --JDHawke
Re^2: (Golf) Tic Tac Toe
by QM (Vicar) on Jun 06, 2004 at 23:56 UTC
    You have a typo I think:
    1 9 4 7 5 3 6 1 8
    1st column and major diagonal do not add to 15.

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

      Run this with an odd argument (like 3) to get a magic square :-)
      print"@{$_=++$_%@F+$p--%@F*@F+1for@F,$p;F} "for@F=0..~-pop

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2014-08-01 02:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (256 votes), past polls