How to resolve the algorithm Solve a Hopido puzzle step by step in the 11l programming language
How to resolve the algorithm Solve a Hopido puzzle step by step in the 11l programming language
Table of Contents
Problem Statement
Hopido puzzles are similar to Hidato. The most important difference is that the only moves allowed are: hop over one tile diagonally; and over two tiles horizontally and vertically. It should be possible to start anywhere in the path, the end point isn't indicated and there are no intermediate clues. Hopido Design Post Mortem contains the following: "Big puzzles represented another problem. Up until quite late in the project our puzzle solver was painfully slow with most puzzles above 7×7 tiles. Testing the solution from each starting point could take hours. If the tile layout was changed even a little, the whole puzzle had to be tested again. We were just about to give up the biggest puzzles entirely when our programmer suddenly came up with a magical algorithm that cut the testing process down to only minutes. Hooray!" Knowing the kindness in the heart of every contributor to Rosetta Code, I know that we shall feel that as an act of humanity we must solve these puzzles for them in let's say milliseconds. Example: Extra credits are available for other interesting designs.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Solve a Hopido puzzle step by step in the 11l programming language
Source code in the 11l programming language
V neighbours = [[2, 2], [-2, 2], [2, -2], [-2, -2], [3, 0], [0, 3], [-3, 0], [0, -3]]
V cnt = 0
V pWid = 0
V pHei = 0
F is_valid(a, b)
R -1 < a & a < :pWid & -1 < b & b < :pHei
F iterate(&pa, x, y, v)
I v > :cnt
R 1
L(i) 0 .< :neighbours.len
V a = x + :neighbours[i][0]
V b = y + :neighbours[i][1]
I is_valid(a, b) & pa[a][b] == 0
pa[a][b] = v
V r = iterate(&pa, a, b, v + 1)
I r == 1
R r
pa[a][b] = 0
R 0
F solve(pz, w, h)
V pa = [[-1] * h] * w
V f = 0
:pWid = w
:pHei = h
L(j) 0 .< h
L(i) 0 .< w
I pz[f] == ‘1’
pa[i][j] = 0
:cnt++
f++
L(y) 0 .< h
L(x) 0 .< w
I pa[x][y] == 0
pa[x][y] = 1
I 1 == iterate(&pa, x, y, 2)
R (1, pa)
pa[x][y] = 0
R (0, pa)
V r = solve(‘011011011111111111111011111000111000001000’, 7, 6)
I r[0] == 1
L(j) 6
L(i) 7
I r[1][i][j] == -1
print(‘ ’, end' ‘’)
E
print(‘ #02’.format(r[1][i][j]), end' ‘’)
print()
E
print(‘No solution!’, end' ‘’)
You may also check:How to resolve the algorithm Scope modifiers step by step in the REXX programming language
You may also check:How to resolve the algorithm Loops/Downward for step by step in the Groovy programming language
You may also check:How to resolve the algorithm Show the epoch step by step in the ABAP programming language
You may also check:How to resolve the algorithm Terminal control/Clear the screen step by step in the Nemerle programming language
You may also check:How to resolve the algorithm Farey sequence step by step in the Maxima programming language