Post on 30-Dec-2015
transcript
Enumeration of Hidato puzzles
Gyora Benedek
solutions
Hidato solution = Hamiltonian path on a grid
2(c) Copyright, Gyora Benedek 2014
How many are th
ere?
Let’s try something easier:2 by n grids
3(c) Copyright, Gyora Benedek 2014
Enumerating 2 by n LR Hamiltonian paths
• LR paths: start at BL and end TR
2 by 6• H(2,6) = ?• H(2,n) = ?
4(c) Copyright, Gyora Benedek 2014
Enumerating 2 by n LR Hamiltonian paths
• Note that for any 2 by n path we can exchange any two values in the same column and get a new path
5(c) Copyright, Gyora Benedek 2014
Enumerating 2 by n LR Hamiltonian paths
• Note that for any 2 by n path we can exchange any two values in the same column and get a new path – both have the same neighbors
6(c) Copyright, Gyora Benedek 2014
Ordered LR 2 by n path
Def. Ordered LR 2 by n path:A 2 by n path where 1 is in the left col., 2n is in
the right col. and in every column the number below is smaller than the number above.
7(c) Copyright, Gyora Benedek 2014
How many ordered LR 2 by n paths?
Def. K(n) = #(ordered LR 2 by n paths)
8(c) Copyright, Gyora Benedek 2014
2 by 1
9
K(1) = 1
(c) Copyright, Gyora Benedek 2014
2 by 2
10
K(2) = 2
(c) Copyright, Gyora Benedek 2014
2 by 6
11
K(6) =?
(c) Copyright, Gyora Benedek 2014
2 by 6
12
K(6) =?
(c) Copyright, Gyora Benedek 2014
2 by 6
13
K(6) =K(5)+?
(c) Copyright, Gyora Benedek 2014
2 by 6
14
K(6) =K(5)+?
(c) Copyright, Gyora Benedek 2014
2 by 6
15
K(6) =K(5)+?
(c) Copyright, Gyora Benedek 2014
2 by 6
16
K(6) =K(5)+K(4)
(c) Copyright, Gyora Benedek 2014
How many ordered LR 2 by n paths
K(1) = 1K(2) = 2K(n) = K(n-1) + K(n-2)
17(c) Copyright, Gyora Benedek 2014
How many ordered LR 2 by n paths?
K(1) = 1K(2) = 2K(n) = K(n-1) + K(n-2)
Fibonacci numbers shifted – as any biologist would recognizeF(1) = 1; F(2) = 1; F(3) = 2; F(n)=F(n-1)+F(n-2)
K(n) = F(n+1)
Interesting to note that this is also the number of ways for 2 by 1 dominoes to cover a 2 by n board.
18(c) Copyright, Gyora Benedek 2014
Enumerating 2 by n LR Hamiltonian paths
Reminder LR: start at BL and end at TR
19
)1(2),2( 2 nFnH n
(c) Copyright, Gyora Benedek 2014
Divide and conquer
(c) Copyright, Gyora Benedek 2014 20
Lower bound by brute force
• 5x5 {?,?} => {A,B}: 83,781,512• 5x4 {C,D} => {E,F}: 202,374• 4x4 {G,H} => {I,J}: 9,868• 4x5 {K,L} => {?,?}: 1,306,425• Symmetries: 16• Total: 3,497,329,213,274,509,542,835,200
(c) Copyright, Gyora Benedek 2014 21
Big numbers
• Rubik’s 3×3×3 cube ≈ 4.3 × 10^19• Sudoku 9×9 ≈ 6.6 × 10^21• Hidato King 9×9 >> 3.49×10^24
× 500
• Still, the lower bound is extremely pessimistic. Can we do better?
(c) Copyright, Gyora Benedek 2014 22
Project proposal: Enumerate all Hamiltonian paths in a 9×9 grid
with diagonals
(c) Copyright, Gyora Benedek 2014 23
A Walk in the shadows
Shadows
2,000,000 774 544(c) Copyright, Gyora Benedek 2014 24
Shadows
(c) Copyright, Gyora Benedek 2014 25
Shadows
• 2,000,000*774*544 = 842,112,000,000 paths(c) Copyright, Gyora Benedek 2014 26
Feasibility
• #shadows – Comb(27,81) ≈ 2.3 × 10^21– Trim non-connected, with holes (? 10^9 ?)– Entry, exit points– If too large try 4 shadows of 20 + 1– Or smaller boards (8×8 even 7×7)
(c) Copyright, Gyora Benedek 2014 27
Challenges
• Efficient algorithms and code• Efficient representation of the shadows
– Shadow: 81bit, entry: 7bit, exit: 7bit, counter: 32?
• Efficient search: hash of the shadow• Parallel/Distributed processing
– Cloud
• Efficient disk access (SSD?) and memory use• Testing: we have data up to 5×5
(c) Copyright, Gyora Benedek 2014 28
Summary
• Numbers are men’s friends – get to know them!– Help the young know them
• Hidato is great for your brain – play and enjoy• Enumeration of Hidato solutions is hard
– Will you pick up the challenge and walk in the shadows?
(c) Copyright, Gyora Benedek 2014 29
Thank You!
Questions?
Ideas?
Visit hidato.com
(c) Copyright, Gyora Benedek 2014 30