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

Home > General
Button puzzle (Posted on 2006-10-13) Difficulty: 2 of 5
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.)
Solution 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    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
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (6)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2017 by Animus Pactum Consulting. All rights reserved. Privacy Information