There are six buttons in a row. Each button shows an arrow pointing left (L) or right (R). When you press a button, all buttons in the direction of its arrow (not including itself) rotate 180 degrees.
Find the least number of button presses required to get from RRRLLL to LRLRLR.
All the ways of doing it in 4 moves:
1354 1462 1534 1543 2164 2515
rrrlll rrrlll rrrlll rrrlll rrrlll rrrlll
rllrrr rllrrr rllrrr rllrrr rrlrrr rrlrrr
lrlrrr rllrll rllrrl rllrrl rlrlll rrlrrl
lrlrrl lrrlrl lrlrrl rllrlr lrlrrl rlrllr
lrlrlr lrlrlr lrlrlr lrlrlr lrlrlr lrlrlr
5262 5613 6234 6243 6315 6423
rrrlll rrrlll rrrlll rrrlll rrrlll rrrlll
lllrll lllrll lllrrl lllrrl lllrrl lllrrl
rllrll rrrlrl rllrrl rllrrl rrlrrl lllrlr
lrrlrl rllrlr lrlrrl rllrlr rlrllr rllrlr
lrlrlr lrlrlr lrlrlr lrlrlr lrlrlr lrlrlr
The sequence of button presses is shown at the top of each group, followed by the list of states that result.
DECLARE SUB move (lvl!)
CLEAR , , 9999
DIM SHARED state$, h(10), hs$(10), sCt
state$ = "rrrlll"
hs$(0) = state$
CLS
move 1
SUB move (lvl)
FOR i = 1 TO 6
IF i <> h(lvl - 1) THEN
hs$(lvl) = ""
h(lvl) = i
IF MID$(hs$(lvl - 1), i, 1) = "l" THEN
FOR j = 1 TO 6
IF j < i THEN
IF MID$(hs$(lvl - 1), j, 1) = "l" THEN
hs$(lvl) = hs$(lvl) + "r"
ELSE
hs$(lvl) = hs$(lvl) + "l"
END IF
ELSE
hs$(lvl) = hs$(lvl) + MID$(hs$(lvl - 1), j, 1)
END IF
NEXT
ELSE
FOR j = 1 TO 6
IF j > i THEN
IF MID$(hs$(lvl - 1), j, 1) = "l" THEN
hs$(lvl) = hs$(lvl) + "r"
ELSE
hs$(lvl) = hs$(lvl) + "l"
END IF
ELSE
hs$(lvl) = hs$(lvl) + MID$(hs$(lvl - 1), j, 1)
END IF
NEXT
END IF
IF hs$(lvl) = "lrlrlr" THEN
sCt = sCt + 1
r0 = ((sCt - 1) \ 6 + 1) * 8
c0 = ((sCt - 1) MOD 6 + 1) * 8
FOR j = 1 TO lvl
LOCATE r0, c0 + j
PRINT LTRIM$(STR$(h(j)));
NEXT
FOR j = 0 TO lvl
LOCATE r0 + j + 1, c0 + 1
PRINT hs$(j);
NEXT
PRINT
ELSE
IF lvl < 4 THEN
move lvl + 1
END IF
END IF
END IF
NEXT
END SUB
|
Posted by Charlie
on 2006-10-13 11:10:45 |