Академический Документы
Профессиональный Документы
Культура Документы
The task is to write a program which solves Hidato (aka Hidoku) puzzles.
The rules are:
You are given a grid with some numbers placed in it. The other squares in the grid
will be blank.
The aim is to place a natural number in each blank square so that in the sequence
of numbered squares from 1 upwards, each square is in the wp:Moore
neighborhood of the squares immediately before and after it in the sequence
(except for the first and last squares, of course, which only have one-sided
constraints).
HOLY KNIGHTS
TOUR
Chess coaches have
been known to inflict a
kind of torture on
beginners by taking a chess board, placing pennies on some squares and requiring that a
Knight's tour be constructed that avoids the squares with pennies.
This kind of knight's tour puzzle is similar to Hidato.
The present task is to produce a solution to such problems. At least demonstrate your
program by solving the following:
Example 1
Note that the zeros represent
the available squares, not
the pennies.
Extra credit is available for
other interesting examples.
HOPIDO PUZZLE
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 77 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:
NUMBRIX PUZZLE
Numbrix puzzles are similar to Hidato. The most important difference is that it is only
possible to move 1 node left, right, up, or down (sometimes referred to as the Von
Neumann neighborhood). Published puzzles also tend not to have holes in the grid and
may not always indicate the end node. Two examples follow:
Example 1
Problem.
0
0 46 45
0 55 74
0 38
0 43
0 78
0 35
0 71
0 33
0 59
0 17
0 67
0 18
0 11
0 64
0 24 21
Solution.
49 50 51 52 53 54 75 76 81
48 47 46 45 44 55 74 77 80
37 38 39 40 43 56 73 78 79
36 35 34 41 42 57 72 71 70
31 32 33 14 13 58 59 68 69
30 17 16 15 12 61 60 67 66
29 18 19 20 11 62 63 64 65
28 25 24 21 10
27 26 23 22
Example 2
Problem.
0
0 11 12 15 18 21 62 61
0 60
0 33
0 57
0 32
0 56
0 37
0 73
0 38
0 72
0 43 44 47 48 51 76 77
Solution.
9 10 13 14 19 20 63 64 65
8 11 12 15 18 21 62 61 66
7
34 33
5 16 17 22 59 60 67
4
3 24 23 58 57 68
35 32 31
2 25 54 55 56 69
36 37 30
1 26 53 74 73 70
39 38 29 28 27 52 75 72 71
40 43 44 47 48 51 76 77 78
41 42 45 46 49 50 81 80 79
Task
Write a program to solve puzzles of this ilk, demonstrating your program by solving the
above examples. Extra credit for other interesting examples.
NO CONNECTION PUZZLE
You are given a box with eight holes labelled A-to-H, connected by fifteen straight lines
in the pattern as shown
Now consider a variant of this problem: you must place an equal number of knights and
queens on a chessboard such that no piece attacks any other piece. What is the maximum
number of pieces you can so place on the board, and how many different ways can you do
it?
The queens and knights problem is considerably more difficult.
Answer:
At most 5 queens and 5 knights can be placed on an 8-by-8 chessboard so that no piece
attacks another.
If reflectional and transpositional variants are considered to be the same, then there are 2
different ways to place the 5 queens and 5 knights.