Specifying successive positions by two digits: rc, where r is the row number and c is the column number, these are the valid paths (11 at the beginning and 66 at the end are assumed):
12 13 14 24 23 33 32 42 41 51 52 62 63 53 54 44 34 35 25 26 36 46 56 55 65
12 13 14 24 23 33 32 42 41 51 52 62 63 53 54 44 34 35 45 55 65
12 13 23 33 32 42 41 51 52 62 63 53 54 44 34 35 25 26 36 46 56 55 65
12 13 23 33 32 42 41 51 52 62 63 53 54 44 34 35 45 55 65
21 31 32 42 41 51 52 62 63 53 54 44 34 35 25 26 36 46 56 55 65
21 31 32 42 41 51 52 62 63 53 54 44 34 35 45 55 65
There are 25 entries in the longest list, and then getting to 66 is one more, for 26 moves in the longest path.
There are 17 entries in the shortest list, and then getting to 66 is one more, for 18 moves in the shortest path.
Translated into terms of the moves (Up, Down, Left or Right) the paths are:
RRRDLDLDLDRDRURUURURDDDLDR
RRRDLDLDLDRDRURUURDDDR
RRDDLDLDRDRURUURURDDDLDR
RRDDLDLDRDRURUURDDDR
DDRDLDRDRURUURURDDDLDR
DDRDLDRDRURUURDDDR
DECLARE SUB goFrom (rf!, cf!)
CLEAR , , 25000
DIM SHARED gu$(6, 6), bd(6, 6), rowHist(36), colHist(36), moveNo
DATA yc,yt,ys,bs,bc,yt
DATA yc,bs,yt,bt,ys,bs
DATA bc,bs,bt,ys,yc,bt
DATA yt,bt,yc,bs,yt,bs
DATA ys,yc,bs,bt,yc,bc
DATA bt,ys,bs,yc,yt,ys
FOR r = 1 TO 6
FOR c = 1 TO 6
READ gu$(r, c)
NEXT
NEXT
bd(1, 1) = 1
goFrom 1, 1
SUB goFrom (rf, cf)
FOR dr = -1 TO 1
FOR dc = -1 TO 1
IF dr = 0 OR dc = 0 THEN
IF dr <> dc THEN
rt = rf + dr: ct = cf + dc
IF rt > 0 AND rt < 7 AND ct > 0 AND ct < 7 THEN
IF LEFT$(gu$(rt, ct), 1) = LEFT$(gu$(rf, cf), 1)
OR RIGHT$(gu$(rt, ct), 1) = RIGHT$(gu$(rf, cf), 1) THEN
IF bd(rt, ct) = 0 THEN
bd(rt, ct) = 1
IF rt = 6 AND ct = 6 THEN
FOR i = 1 TO moveNo
PRINT LTRIM$(STR$(rowHist(i)));
LTRIM$(STR$(colHist(i))); " ";
NEXT i
PRINT
ELSE
moveNo = moveNo + 1
rowHist(moveNo) = rt
colHist(moveNo) = ct
goFrom rt, ct
moveNo = moveNo - 1
END IF
bd(rt, ct) = 0
END IF
END IF
END IF
END IF
END IF
NEXT
NEXT
END SUB
translation of the form of the answer by:
OPEN "mensmzan.txt" FOR INPUT AS #1
DO
LINE INPUT #1, l$
l$ = LTRIM$(RTRIM$(l$)) + " 66 "
v$ = "1": h$ = "1"
DO
ix = INSTR(l$, " ")
IF ix = 0 THEN EXIT DO
newV$ = LEFT$(l$, 1): newH$ = MID$(l$, 2, 1)
l$ = LTRIM$(MID$(l$, ix + 1))
dv = VAL(newV$) - VAL(v$)
dh = VAL(newH$) - VAL(h$)
SELECT CASE dv
CASE -1
PRINT "U";
CASE 1
PRINT "D";
CASE 0
SELECT CASE dh
CASE -1
PRINT "L";
CASE 1
PRINT "R";
END SELECT
END SELECT
v$ = newV$: h$ = newH$
LOOP
PRINT
LOOP UNTIL EOF(1)
From the Mensa puzzle calendar for 2009, by Dr. Abbie F. Salny, Mark Danna and Fraser Simpson, Workman Publishing, New York. Puzzle for September 24.
|