SLIDE 1
The Algorithmics of Solitaire-Like Games
Roland Backhouse Wei Chen Jo˜ ao F. Ferreira University of Nottingham
SLIDE 2 Algorithmic Problem Solving
- 1st-year, 1st-semester
- compulsory since 2006, previously optional
- problem-driven
- introduction to mathematics of program construction
SLIDE 3 The Bridge Problem
4 people want to cross a bridge. Person 1 takes 1 minute to cross the bridge. Person 2 takes 2 minute to cross the bridge. Person 3 takes 5 minute to cross the bridge. Person 4 takes 10 minute to cross the bridge. The bridge is narrow and only 2 people can cross together. It is dark and they have only one torch. When someone is
- n the bridge they must have the torch with them.
Show that everyone can cross in 17 minutes.
SLIDE 4 The Bridge Problem
N people want to cross a bridge. Person i takes t.i minute to cross the bridge. The bridge is narrow and only 2 people can cross together. It is dark and they have only one torch. When someone is
- n the bridge they must have the torch with them.
Develop an algorithm to get all people across in the shortest possible time.
SLIDE 5
Seven-trees In One
(unlabelled) binary trees: T ∼ = 1 + T 2 generates T 7 ∼ = T 1
SLIDE 6
Seven-trees In One
fission fusion
T k × T 1 → T k × (T 0 + T 2) T k × (T 0 + T 2) → T k × T 1
goal
T 1 T 7
SLIDE 7
Peg Solitaire
SLIDE 8
Weight of a Peg
j i
Weight : pi+j Total weight = sum of weights of all pegs
SLIDE 9
Peg Solitaire
horizontal-right move pi+j + pi+j+1 → pi+j+2 pi+j × (p0 + p1) → pi+j × p2 p0 + p1 → p2
SLIDE 10
Peg Solitaire
vertical-down move pi+j+2 + pi+j+1 → pi+j+0 p2 + p1 → p0
SLIDE 11 The Total Weight is invariant if
horizontal-right vertical-up
horizontal-left vertical-down
SLIDE 12
GF(4)
Semi-ring (in fact, a field) with 4 elements { 0, 1, p, p2 } + 1 p p2 1 p p2 1 1 p2 p p p p2 1 p2 p2 p 1
SLIDE 13
Conclusion: Weight in GF(4) is invariant under all moves. Hence positions are divided into 4 equivalence classes. Symmetrically: Assign weight pi−j to peg at position (i, j). Then positions are divided into 4 equivalence classes. Corollary (De Bruijn 1972, Reiss 1857) : Sixteen different equivalence classes.
SLIDE 14
Solitaire Army (Conway, 1961)
A number of Solitaire men stand initially on one side of a straight line beyond which is an infinite empty desert. How many men do we need to send a scout just 0, 1, 2, 3, 4 or 5 paces out into the desert?
n
SLIDE 15 Monovariant (“Pagoda Function”)
A monovariant is a function from the state space to a partially
- rdered set that is monotonic with respect to the transition
relation. (I.e. s → t ⇒ f.s f.t .)
SLIDE 16 Solitaire Army
Label position to be reached (0, 0). Suppose Solitaire men are all initially at positions (i, j) such that n j. Assign to peg at position (i, j) the weight σi+j. Choose σ so that the total weight is a monovariant. σ2 + σ = 1, σ2 1 + σ σ = √ 5 − 1 2 . Maximum initial weight < σn−5 , Goal state has weight 1 .
SLIDE 17 Tiling Problem
Given an m × m board, one 1-omino and an unlimited supply
- f n-ominoes, when is it possible to completely tile the board?
Example: m = 3, n = 2
1-omino 2-omino
SLIDE 18
Tiling Problem
Solution: 1 = m ∨ (1 n < m ∧ (n \ (m − 1) ∨ n \ (m + 1))) . Sufficient:
m-1 m-1 n n m+1-n m+1-n
n \ m − 1 n \ m + 1
SLIDE 19 Tiling Problem
Necessary: Let R = (A, 0, 1, +, ·) be any semiring with an element x s.t. Σ i : 0 i < n : xi =R 0 . Assign to square (i, j) the weight xi+j if the square is covered ;
The total weight is invariant under placement
- f an n-omino on the board.
SLIDE 20 Tiling Problem
The total weight is invariant under placement
- f an n-omino on the board.
Necessary condition : ∃ k : : xk =R Σ i, j : 0 i, j < m : xi+j . ↑ weight of board with one 1-omino (initial state) ↑ weight of totally covered board (final state)
SLIDE 21
Tiling Problem
Choice of semiring R : R = GF(2)[x]/ Σ i : 0 i < n : xi (set of polynomials in indeterminate x with coefficients in GF(2) modulo Σ i : 0 i < n : xi ) ∃ k : : xk =R Σ i, j : 0 i, j < m : xi+j ⇒ { P =R xk ⇒ #P = 1 ∨ #P = n − 1 } (m mod n = 1) ∨ (m mod n = n − 1)
SLIDE 22
Seven-trees In One
fission fusion
T k × T 1 → T k × (T 0 + T 2) T k × (T 0 + T 2) → T k × T 1
goal
T 1 T 7
SLIDE 23 Seven-trees In One
1 2 3 4 5 6 7 8
- T 1+(γ+T 4 + T 5)×(1−T+T 2) = T 7+(γ+T 1 + T 2)×(1−T+T 2)
SLIDE 24
Cyclotomic constraints: T ∼ = T + Ψ
◮ Ψ is a product of cyclotomic polynomials; ◮ Ψ’s degree is at least 2; ◮ coefficients of T + Ψ are positive.
T 1 − 1 = (T − 1) × (T + 1) × (T 2 + T + 1) × (T 1 − T + 1) T ∼ = 1 + T 2 {T 1 − T + 1} ; T ∼ = 1 + 2T + T 2 {T 2 + T + 1} ; T ∼ = 1 + T + T 2 + T 4 {(T 2 + T + 1)(T 1 − T + 1)} .
SLIDE 25
Cyclotomic Games
Ψa,n = Σ i : 0 i < a : T i×an−1 (2 a ∧ 2 n) ∨ (3 a ∧ 1 = n) — product of cyclotomic polynomials of degree at least 2.
SLIDE 26
Cyclotomic Games
move : T = T + Ψa,n goal : T an+1 − T = (T an−1+1 − T) × Ψa,n Example : Ψ2,3 = 1 + T 4 move : goal : move one checker 8 places to right.
SLIDE 27
Algorithm
{ s = T } expand { s = T + (γ + T an−1+1) × Ψa,n } { s = T an+1 + (γ + T) × Ψa,n } contract { s = T an+1 }
SLIDE 28
Contract note: Ψa,n = 1 + . . . an expansion always adds a checker one place to the left of expanded checker.
SLIDE 29 Contract { s = T an+1 + Σ i : 0 i < an + 1 : T i × Ψa,n } k := 0; { Invariant : s = T an+1 + Σ k : k i < an + 1 : T i × Ψa,n } do k < an + 1 → s, k := s − T k × Ψa,n, k + 1
{ s = T an+1 }
SLIDE 30 Expand Let E = { i : 2 i < an + 1 : i + 1 } ⊎ { an−1 + 2 } { s = T + Ψa,n } A, B := E, ∅; { Invariant : s = T + Σ i : i ∈ { 1 } ⊎ B : T i−1 × Ψa,n ∧ A ⊎ B = E} do A = ∅ → choose j ∈ A such that there is a checker in position j ; s := s + T j−1 × Ψa,n ; A, B := A − { j }, B ⊎ { j } ;
{ s = T + Σ i : i ∈ { 1 } ⊎ E : T i−1 × Ψa,n }
SLIDE 31 Solution For Example
1 2 3 4 5 6 7 8 9 10 11 12
- T 1 + (γ + T 5) × (1 + T 4) = T 9 + (γ + T 1) × (1 + T 4)
SLIDE 32 Conclusion
- Goal is to develop exercises in algorithmic problem solving
- non-mathematical problem statement
- mathematical solution