All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 2-way maze (Posted on 2004-11-01)
An Invisible Maze is a square room with a tiled floor, in which the tiles form a grid. You may walk only to adjacent tiles (no diagonal moves). There is a number on the wall for each row and column of tiles. An Invisible Maze can have any numbers on the walls provided that it has at least one True Path. A True Path will take you from the northwest corner to the southeast corner, and the number of tiles you touch in each row and column is equal to the corresponding number on the wall.

There is an NxN tiled Invisible maze that has at least two different True Paths. Minimize N and then, using that N, minimize the sum of all the numbers on the wall.

Important: Two paths are considered the same even if they touch the exact same tiles in a different order.

 See The Solution Submitted by Tristan Rating: 3.6667 (3 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
 computer verification of minimum Comment 20 of 20 |

When the output of the below program is sorted and examined, no valid results are found for sz = 4, and the lowest total found for sz = 5 is indeed 26, for which there are three basic solutions, each with a possible flip about the main diagonal.

CLEAR , , 25000
DIM SHARED sz
sz = 4
DIM SHARED gr(sz, sz), wall(2 * sz), row, col, path(sz * sz)

OPEN "mzpath" + LTRIM\$(STR\$(sz)) + ".txt" FOR OUTPUT AS #2

gr(1, 1) = 1

row = 1: col = 1: path(1) = 1

FOR drow = -1 TO 1
FOR dcol = -1 TO 1
IF ABS(drow) + ABS(dcol) = 1 THEN
newrow = row + drow: newcol = col + dcol
IF newrow > 0 AND newrow <= sz AND newcol > 0 AND newcol <= sz THEN
IF gr(newrow, newcol) = 0 THEN
oldcol = col: oldrow = row
row = newrow: col = newcol
gr(row, col) = 1
path(lv) = sz * (row - 1) + col
IF row = sz AND col = sz THEN
walltot = 0
FOR r = sz TO 1 STEP -1
t = 0
FOR c = 1 TO sz
IF gr(r, c) THEN t = t + 1
NEXT
wall(sz - r + 1) = t
walltot = walltot + t
NEXT
FOR c = 1 TO sz
t = 0
FOR r = 1 TO sz
IF gr(r, c) THEN t = t + 1
NEXT
wall(sz + c) = t
walltot = walltot + t
NEXT
PRINT #2, USING "### "; walltot;
FOR i = 1 TO 2 * sz
PRINT #2, USING "### "; wall(i);
NEXT
FOR r = 1 TO sz: FOR c = 1 TO sz
IF gr(r, c) THEN PRINT #2, "x";: ELSE PRINT #2, " ";
NEXT: NEXT
FOR i = 1 TO lv
PRINT #2, USING "###"; path(i);
NEXT
PRINT #2,
ELSE
END IF
gr(row, col) = 0
row = oldrow: col = oldcol
END IF
END IF
END IF
NEXT
NEXT
END SUB

The relevant output lines are (with annotations added):

`                wall numbers                    occupied positions                pathtotal left(bottom to top) top(left to right)   (reading order--             by position number                                                 top-to-bottom and             as at left                                                   left to right)`
` 26   1   1   3   5   3   2   2   3   2   4 x xx xxxxx xx x    x    x  1  6  7 12 13  8  3  4  9 10 15 20 25 26   1   1   3   5   3   2   2   3   2   4 xxx  xxxxx  xxx    x    x  1  6  7  2  3  8 13 14  9 10 15 20 25`
` 26   1   3   5   3   1   3   2   3   2   3 x    x xx xxxxx xx x    x  1  6 11 12 17 18 13  8  9 14 15 20 25 26   1   3   5   3   1   3   2   3   2   3 x    xxx  xxxxx  xxx    x  1  6 11 12  7  8 13 18 19 14 15 20 25`
` 26   2   2   3   2   4   1   1   3   5   3 xxxx    xx  xxx  xx    xx  1  2  3  4  9 10 15 14 13 18 19 24 25 26   2   2   3   2   4   1   1   3   5   3 xxxx   xx   xxx   xx   xx  1  2  3  4  9  8 13 14 15 20 19 24 25`
` 26   3   2   3   2   3   1   3   5   3   1 xxx    xx  xxx  xx    xxx  1  2  3  8  9 14 13 12 17 18 23 24 25 26   3   2   3   2   3   1   3   5   3   1 xxx   xx   xxx   xx   xxx  1  2  3  8  7 12 13 14 19 18 23 24 25`
` 26   3   5   3   1   1   4   2   3   2   2 x    x    x xx xxxxx xx x  1  6 11 16 17 22 23 18 13 14 19 20 25 26   3   5   3   1   1   4   2   3   2   2 x    x    xxx  xxxxx  xxx  1  6 11 16 17 12 13 18 23 24 19 20 25`
` 26   4   2   3   2   2   3   5   3   1   1 xx    xx  xxx  xx    xxxx  1  2  7  8 13 12 11 16 17 22 23 24 25 26   4   2   3   2   2   3   5   3   1   1 xx   xx   xxx   xx   xxxx  1  2  7  6 11 12 13 18 17 22 23 24 25 `

The diagrams below represent the three basic solutions, which can be flipped about a diagonal. The paths are shown below in hexadecimal to alleviate crowding.

`    2 2 3 2 4          2 2 3 2 4 3 1   7 8          3 1 4 5 5 2 3 6 9 A        5 2 3 6 9 A 3   4 5   B        3     7 8 B 1         C        1         C 1         D        1         D      3 2 3 2 3          3 2 3 2 3  1 1               1  1  3 2   8 9         3  2 5 6  5 3 4 7 A B       5  3 4 7 A B  3   5 6   C       3      8 9 C  1         D       1          D       1 1 3 5 3          1 1 3 5 3  4 1 2 3 4         4  1 2 3 4      2       5 6       2      6 5      3     9 8 7       3      7 8 9    2     A B         2        B A    2       C D       2        C D  `
` `

Edited on August 18, 2013, 6:45 pm
 Posted by Charlie on 2013-08-18 14:31:49

 Search: Search body:
Forums (0)