All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Probability
Random Tic Tac Toe (Posted on 2025-02-17) Difficulty: 3 of 5
If every move in a game of tic-tac-toe is made at random, spread evenly over the remaining spaces, what is the probability the first player wins, the second player wins, or that there is a tie?

See The Solution Submitted by Charlie    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Simulation | Comment 1 of 2
With a million runs, probabilities I found:
1stWins   2ndWins     Draw
0.585064 0.287874 0.127062

Broken down by after how many moves the game was won:
5: 0.11
6: 0.1
7: 0.3
8: 0.23
9: 0.26

----
import random
xwins = 0
owins = 0
draws = 0

wins = [{1,2,3},{4,5,6},{7,8,9},
        {1,4,7},{2,5,8},{3,6,9},
        {1,5,9},{3,5,7}]
nums = [1,2,3,4,5,6,7,8,9]

durations = [0 for i in range(9)]
iters = 1000000
for iter in range(iters):
    done = False
    tics = random.sample(nums, 5)
    for w in wins:
        if w&set(tics[0:5:2]) == w:
            xwins += 1
            done = True
            durations[4] += 1
            break
    if done:
        continue
    remains = [n for n in nums if n not in tics]
    tics.append(random.choice(remains))
    for w in wins:
        if w&set(tics[1:6:2]) == w:
            owins += 1
            done = True
            durations[5] += 1
            break
    if done:
        continue
    remains = [n for n in nums if n not in tics]
    tics.append(random.choice(remains))
    for w in wins:
        if w&set(tics[0:7:2]) == w:
            xwins += 1
            done = True
            durations[6] += 1
            break
    if done:
        continue
    remains = [n for n in nums if n not in tics]
    tics.append(random.choice(remains))
    for w in wins:
        if w&set(tics[1:8:2]) == w:
            owins += 1
            done = True
            durations[7] += 1
            break
    if done:
        continue
    remains = [n for n in nums if n not in tics]
    tics.append(random.choice(remains))
    for w in wins:
        if w&set(tics[0:9:2]) == w:
            xwins += 1
            done = True
            durations[8] += 1
            break
    if done:
        continue
    draws += 1

mysum = sum((xwins,owins,draws))
print(xwins/mysum,owins/mysum,draws/mysum )

othersum = sum(durations)
for i in range(4,9):
    print('{}: {}'.format(i+1, round(durations[i]/othersum,2)))

Edited on February 17, 2025, 7:37 am
  Posted by Larry on 2025-02-17 07:33:01

Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (4)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2025 by Animus Pactum Consulting. All rights reserved. Privacy Information