the algorithmics of solitaire like games
play

The Algorithmics of Solitaire-Like Games Roland Backhouse Wei Chen - PowerPoint PPT Presentation

The Algorithmics of Solitaire-Like Games Roland Backhouse Wei Chen Jo ao F. Ferreira University of Nottingham Algorithmic Problem Solving 1st-year, 1st-semester compulsory since 2006, previously optional problem-driven


  1. The Algorithmics of Solitaire-Like Games Roland Backhouse Wei Chen Jo˜ ao F. Ferreira University of Nottingham

  2. Algorithmic Problem Solving ◦ 1st-year, 1st-semester ◦ compulsory since 2006, previously optional ◦ problem-driven ◦ introduction to mathematics of program construction

  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 on the bridge they must have the torch with them. Show that everyone can cross in 17 minutes.

  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 on the bridge they must have the torch with them. Develop an algorithm to get all people across in the shortest possible time.

  5. Seven-trees In One (unlabelled) binary trees: T ∼ = 1 + T 2 generates T 7 ∼ = T 1

  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

  7. Peg Solitaire

  8. Weight of a Peg j Weight : p i + j i Total weight = sum of weights of all pegs

  9. Peg Solitaire horizontal-right move p i + j + p i + j + 1 → p i + j + 2 p i + j × ( p 0 + p 1 ) → p i + j × p 2 p 0 + p 1 → p 2

  10. Peg Solitaire vertical-down move p i + j + 2 + p i + j + 1 → p i + j + 0 p 2 + p 1 → p 0

  11. The Total Weight is invariant if � horizontal-right p 0 + p 1 = p 2 vertical-up � horizontal-left p 0 = p 1 + p 2 vertical-down

  12. GF ( 4 ) Semi-ring (in fact, a field) with 4 elements { 0, 1, p , p 2 } p 2 + 0 1 p p 2 0 0 1 p 1 1 0 p 2 p p 2 p p 0 1 p 2 p 2 1 0 p

  13. Conclusion: Weight in GF ( 4 ) is invariant under all moves. Hence positions are divided into 4 equivalence classes. Symmetrically: Assign weight p i − 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.

  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

  15. Monovariant (“Pagoda Function”) A monovariant is a function from the state space to a partially ordered set that is monotonic with respect to the transition relation. (I.e. s → t ⇒ f . s � f . t .)

  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 , � Impossible for 5 � n . Goal state has weight � 1 .

  17. Tiling Problem Given an m × m board, one 1-omino and an unlimited supply of n -ominoes, when is it possible to completely tile the board? Example: m = 3, n = 2 1-omino 2-omino

  18. Tiling Problem Solution: 1 = m ∨ ( 1 � n < m ∧ ( n \ ( m − 1 ) ∨ n \ ( m + 1 ))) . Sufficient: n m+1-n m-1 n m-1 m+1-n n \ m − 1 n \ m + 1

  19. Tiling Problem Necessary: Let R = ( A , 0, 1, + , · ) be any semiring with an element x s.t. � Σ i : 0 � i < n : x i � = R 0 . Assign to square ( i , j ) the weight x i + j if the square is covered ; 0 otherwise . The total weight is invariant under placement of an n -omino on the board.

  20. Tiling Problem The total weight is invariant under placement of an n -omino on the board. Necessary condition : � ∃ k : : x k = R � Σ i , j : 0 � i , j < m : x i + j �� . ↑ ↑ weight of board with one weight of totally covered board 1-omino (initial state) (final state)

  21. Tiling Problem Choice of semiring R : R = GF ( 2 )[ x ] / � Σ i : 0 � i < n : x i � (set of polynomials in indeterminate x with coefficients in GF ( 2 ) modulo � Σ i : 0 � i < n : x i � ) � ∃ k : : x k = R � Σ i , j : 0 � i , j < m : x i + j � { P = R x k ⇒ # P = 1 ∨ # P = n − 1 } ⇒ ( m mod n = 1 ) ∨ ( m mod n = n − 1 )

  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

  23. Seven-trees In One 0 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 )

  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 + 1 } ; ∼ = 1 + T 2 T { T 2 + T + 1 } ; ∼ = 1 + 2T + T 2 T = 1 + T + T 2 + T 4 { ( T 2 + T + 1 )( T 1 − T + 1 ) } . ∼ T

  25. Cyclotomic Games Ψ a , n = � Σ i : 0 � i < a : T i × a n − 1 � ( 2 � a ∧ 2 � n ) ∨ ( 3 � a ∧ 1 = n ) — product of cyclotomic polynomials of degree at least 2.

  26. Cyclotomic Games move : T = T + Ψ a , n T a n + 1 − T = ( T a n − 1 + 1 − T ) × Ψ a , n goal : Example : Ψ 2,3 = 1 + T 4 move : goal : move one checker 8 places to right.

  27. Algorithm { s = T } expand { s = T + ( γ + T a n − 1 + 1 ) × Ψ a , n } { s = T a n + 1 + ( γ + T ) × Ψ a , n } contract { s = T a n + 1 }

  28. Contract note: Ψ a , n = 1 + . . . an expansion always adds a checker one place to the left of expanded checker.

  29. Contract { s = T a n + 1 + � Σ i : 0 � i < a n + 1 : T i � × Ψ a , n } k := 0; { Invariant : s = T a n + 1 + � Σ k : k � i < a n + 1 : T i � × Ψ a , n } do k < a n + 1 → s , k := s − T k × Ψ a , n , k + 1 od { s = T a n + 1 }

  30. Expand Let E = { i : 2 � i < a n + 1 : i + 1 } ⊎ { a n − 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 } ; od { s = T + � Σ i : i ∈ { 1 } ⊎ E : T i − 1 � × Ψ a , n }

  31. Solution For Example 0 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 )

  32. Conclusion ◦ Goal is to develop exercises in algorithmic problem solving ◦ non-mathematical problem statement ◦ mathematical solution

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend