tic tac blah

Discussion of challenges you have already solved
Post Reply
paradox.is.taken
Posts: 14
Joined: Mon Oct 20, 2008 2:04 am

tic tac blah

Post by paradox.is.taken »

So anybody else thinks the "clarification" in parenthesis for what not to do is actually the same as the problem?!?

Here is my python code, since the problem was small enough there was no issues with recursion depth or speed.

Code: Select all

draws=0.0
game=0.0

def move(L,player):
    global draws,game
    if(L[0]==L[1]==L[2]!=0 or L[3]==L[4]==L[5]!=0 or L[6]==L[7]==L[8]!=0 or L[0]==L[4]==L[8]!=0 or L[2]==L[4]==L[6]!=0 or L[2]==L[5]==L[8]!=0 or L[1]==L[4]==L[7]!=0 or L[0]==L[3]==L[6]!=0):
        game+=1
        return
    empty=[]
    for i,p in enumerate(L):
        if(p==0):
            empty.append(i)
    if(empty==[]):
        draws+=1
        game+=1
        return
    else:
        for k in empty: 
            newL=L[:]
            newL[k]=player
            move(newL,player%2+1)

L=[0 for i in range(9)]
L[4]=1
move(L,2)
print draws/game
[/quote]
gfoot
Posts: 269
Joined: Wed Sep 05, 2007 11:34 pm
Location: Brighton, UK

Post by gfoot »

I don't remember exactly, but I do remember misinterpreting the problem statement the first time, even with the clarification there!
Post Reply