 All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars  perplexus dot info  Button puzzle (Posted on 2006-10-13) 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.

 See The Solution Submitted by Tristan Rating: 4.0000 (1 votes) Comments: ( Back to comment list | You must be logged in to post comments.) All the ways using the least presses | Comment 3 of 6 | All the ways of doing it in 4 moves:

`1354    1462    1534    1543    2164    2515rrrlll  rrrlll  rrrlll  rrrlll  rrrlll  rrrlllrllrrr  rllrrr  rllrrr  rllrrr  rrlrrr  rrlrrrlrlrrr  rllrll  rllrrl  rllrrl  rlrlll  rrlrrllrlrrl  lrrlrl  lrlrrl  rllrlr  lrlrrl  rlrllrlrlrlr  lrlrlr  lrlrlr  lrlrlr  lrlrlr  lrlrlr`
`5262    5613    6234    6243    6315    6423rrrlll  rrrlll  rrrlll  rrrlll  rrrlll  rrrllllllrll  lllrll  lllrrl  lllrrl  lllrrl  lllrrlrllrll  rrrlrl  rllrrl  rllrrl  rrlrrl  lllrlrlrrlrl  rllrlr  lrlrrl  rllrlr  rlrllr  rllrlrlrlrlr  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 Please log in:

 Search: Search body:
Forums (0)