Skip to content

Instantly share code, notes, and snippets.

@natemcintosh
Created October 10, 2025 15:08
Show Gist options
  • Select an option

  • Save natemcintosh/eda6621983205307c014c4f9972884d2 to your computer and use it in GitHub Desktop.

Select an option

Save natemcintosh/eda6621983205307c014c4f9972884d2 to your computer and use it in GitHub Desktop.
tic-tac-deal
### A Pluto.jl notebook ###
# v0.20.19
using Markdown
using InteractiveUtils
# ╔═╡ 87b56f06-a5e7-11f0-bc5d-fd4c15c7ba48
begin
using Pkg
Pkg.activate(".")
using StaticArrays, Chairmarks
end
# ╔═╡ 82ef12a8-9668-44b9-a93d-21a80618b794
md"""
# [Let's make a tic-tac-deal](https://thefiddler.substack.com/p/lets-make-a-tic-tac-deal)
From Nicholas Smith comes a puzzle about a modified version of tic-tac-toe:
The game of Tic-Tac-Deal 2.0 has a 3-by-3 square grid with the numbers 3 through 11, arranged as follows:
3 4 5
6 7 8
9 10 11
You start by rolling a standard pair of six-sided dice and add the two numbers rolled. You place an `X` on the board on the square that contains the sum. If the sum is a 2 or 12, your roll is wasted.
If you have exactly three rolls of the dice, what are your chances of getting three `X`s in a row (either horizontally, vertically, or diagonally)?
"""
# ╔═╡ 3b47ec7d-ada1-4eb3-ad1b-fc2d84854f83
function create_p_table()
ps = zeros(Int, 12)
for d1 in 1:6, d2 in 1:6
ps[d1+d2] += 1
end
# Go from possible ways to reach that count,
# to probabilities by dividing by total number
# of possibilities
SVector{12, Rational}(ps // 36)
end
# ╔═╡ c3634dd4-edeb-46cd-9e40-b3667d1976bd
@assert sum(create_p_table()) == 1.0
# ╔═╡ 38cb0ac3-e24c-4a97-8c43-db9df3dc3805
ps = create_p_table()
# ╔═╡ fa3017ac-bf73-485a-8316-0e1d456ddc48
calc_unit(ps, r1, r2, r3) = ps[r1] * ps[r2] * ps[r3]
# ╔═╡ 72a9c6b3-ccd8-43f3-b453-11738b908a10
function p_win(ps)
# Add up the probability of getting each
# row, column, and diagonal
calc_unit(ps, 3, 6, 9) + calc_unit(ps, 4, 7, 10) + calc_unit(ps, 5, 8, 11) +
calc_unit(ps, 3, 4, 5) + calc_unit(ps, 6, 7, 8) + calc_unit(ps, 9, 10, 11) +
calc_unit(ps, 3, 7, 11) + calc_unit(ps, 5, 7, 9)
end
# ╔═╡ dc723e20-22b1-4735-a1c9-5d4976f08017
@be p_win(ps)
# ╔═╡ fcc004f0-2f94-41b8-8c9b-e2b866c5d685
Float64(p_win(ps))
# ╔═╡ Cell order:
# ╠═87b56f06-a5e7-11f0-bc5d-fd4c15c7ba48
# ╟─82ef12a8-9668-44b9-a93d-21a80618b794
# ╠═3b47ec7d-ada1-4eb3-ad1b-fc2d84854f83
# ╠═c3634dd4-edeb-46cd-9e40-b3667d1976bd
# ╠═38cb0ac3-e24c-4a97-8c43-db9df3dc3805
# ╠═fa3017ac-bf73-485a-8316-0e1d456ddc48
# ╠═72a9c6b3-ccd8-43f3-b453-11738b908a10
# ╠═dc723e20-22b1-4735-a1c9-5d4976f08017
# ╠═fcc004f0-2f94-41b8-8c9b-e2b866c5d685
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment