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

Home > General
Sliding Coin puzzle (Posted on 2013-06-19) Difficulty: 3 of 5
Start with the sequence of coins as follows (where you can think of O as TAILS and X as HEADS; there are 14 tails and 15 heads)

XOXOXOXOXOXOXOXOXOXOXOXOXOXOX

Transform it to

XXXXXXXXXXXXXXXOOOOOOOOOOOOOO

using moves of the following sort:

Take two consecutive coins and move them to the end, or the beginning.

No Solution Yet Submitted by Danish Ahmed Khan    
Rating: 3.5000 (2 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution solution | Comment 1 of 3

Arrowheads show the direction the chosen pair is to go, for the sequence that follows each:

xoxoxoxoxoxoxoxoxoxoxoxoxoxox
  >>
xoxoxoxoxoxoxoxoxoxoxoxoxoxxo
                          <<
xxxoxoxoxoxoxoxoxoxoxoxoxoxoo
    >>
xxxoxoxoxoxoxoxoxoxoxoxoxooxo
                         >>
xxxoxoxoxoxoxoxoxoxoxoxoxxooo
    >>
xxxoxoxoxoxoxoxoxoxoxoxxoooxo
                      <<
xxxxxoxoxoxoxoxoxoxoxoxooooxo
                       >>
xxxxxoxoxoxoxoxoxoxoxoxooxooo
                       >>
xxxxxoxoxoxoxoxoxoxoxoxxooooo
      >>
xxxxxoxoxoxoxoxoxoxoxxoooooxo
                    <<
xxxxxxxoxoxoxoxoxoxoxooooooxo
                     >>
xxxxxxxoxoxoxoxoxoxoxooooxooo
                     >>
xxxxxxxoxoxoxoxoxoxoxooxooooo
                     >>
xxxxxxxoxoxoxoxoxoxoxxooooooo
        >>
xxxxxxxoxoxoxoxoxoxxoooooooxo
                  <<
xxxxxxxxxoxoxoxoxoxooooooooxo
                   >>
xxxxxxxxxoxoxoxoxoxooooooxooo
                   >>
xxxxxxxxxoxoxoxoxoxooooxooooo
                   >>
xxxxxxxxxoxoxoxoxoxooxooooooo
                   >>
xxxxxxxxxoxoxoxoxoxxooooooooo
          >>
xxxxxxxxxoxoxoxoxxoooooooooxo
                <<
xxxxxxxxxxxoxoxoxooooooooooxo
                 >>
xxxxxxxxxxxoxoxoxooooooooxooo
                 >>
xxxxxxxxxxxoxoxoxooooooxooooo
                 >>
xxxxxxxxxxxoxoxoxooooxooooooo
                 >>
xxxxxxxxxxxoxoxoxooxooooooooo
                 >>
xxxxxxxxxxxoxoxoxxooooooooooo
            >>
xxxxxxxxxxxoxoxxoooooooooooxo
              <<
xxxxxxxxxxxxxoxooooooooooooxo
               >>
xxxxxxxxxxxxxoxooooooooooxooo
               >>
xxxxxxxxxxxxxoxooooooooxooooo
               >>
xxxxxxxxxxxxxoxooooooxooooooo
               >>
xxxxxxxxxxxxxoxooooxooooooooo
               >>
xxxxxxxxxxxxxoxooxooooooooooo
               >>
xxxxxxxxxxxxxoxxooooooooooooo
              <<
xxxxxxxxxxxxxxxoooooooooooooo

The strategy is:

If any xx pairs exist after the first o (any o, even single) bring them to the front, repeating this until no more such exist.

Then, if any oo pairs exist with at least one x after that pair, bring it to the end, repeating this until no more such exist.

If any xo pairs exist after the first o, move it to the end.

Keep repeating the above three steps until completed.

The program that follows this strategy and produced the results above is:


CLS
FOR i = 1 TO 14
  s$ = s$ + "xo"
NEXT
s$ = s$ + "x"

PRINT s$
OPEN "slidcoin.txt" FOR OUTPUT AS #2
PRINT #2, s$

DO
  DO
    ixo = INSTR(s$, "o")
    ix = INSTR(ixo, s$, "xx")
    IF ix > 0 THEN
     s$ = "xx" + MID$(s$, 1, ix - 1) + MID$(s$, ix + 2)
     PRINT SPACE$(ix - 1) + "<<"
     PRINT s$
     PRINT #2, SPACE$(ix - 1) + "<<"
     PRINT #2, s$
    END IF
  LOOP UNTIL ix = 0
  DO
  ix = INSTR(s$, "oo")
  done = 0
  IF ix > 0 THEN
    IF INSTR(ix, s$, "x") THEN
     s$ = LEFT$(s$, ix - 1) + MID$(s$, ix + 2) + "oo"
     PRINT SPACE$(ix - 1) + ">>"
     PRINT s$
     PRINT #2, SPACE$(ix - 1) + ">>"
     PRINT #2, s$
     done = 1
    END IF
  END IF
  LOOP UNTIL done = 0
  ixo = INSTR(s$, "o")
  ix = INSTR(ixo, s$, "xo")
  IF ix > 0 THEN
   IF MID$(s$, ix - 1, 1) <> "x" THEN
     s$ = LEFT$(s$, ix - 1) + MID$(s$, ix + 2) + "xo"
     PRINT SPACE$(ix - 1) + ">>"
     PRINT s$
     PRINT #2, SPACE$(ix - 1) + ">>"
     PRINT #2, s$
   END IF
  END IF
LOOP UNTIL INSTR(s$, "o") = 16
CLOSE


  Posted by Charlie on 2013-06-19 14:02:06
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 (0)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

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