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

Home > General
Trading Places 2 (Posted on 2022-11-16) Difficulty: 3 of 5
Four white markers are placed on the first four squares of a row of nine squares. There is a space of one square and then four black markers.

  • White markers can only move right.
  • Black markers can only move left.
  • Markers can move forward one square, or can jump over a marker of either colour if there is an empty square to land on.
  • Markers are not removed from the board if jumped.
  • You DO NOT have to alternate moving black and white markers.

How can you get the markers to exchange places?

+---+---+---+---+---+---+---+---+---+
| W | W | W | W |   | B | B | B | B |
+---+---+---+---+---+---+---+---+---+

See The Solution Submitted by K Sengupta    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution (spoiler) | Comment 1 of 7
clc
global history

board=['r1';'r2';'r3';'r4';'  ';'l1';'l2';'l3';'l4'];

history={board};

addon

function addon
global history
  board=history{end};
  bareBoard=board(:,1);
  blank=strfind(bareBoard',' ');
  if isequal(bareBoard,['llll rrrr']')
    disp(' ')
    disp(length(history))
    for i=1:length(history)
      disp(history{i}')
      disp(' ')
    end    
  else
    for i = 1:length(board)
      if bareBoard(i)=='r'
         if i==blank-1 || i==blank-2
            saveBoard=board;
            saveHist=history;
            board(blank,:)=board(i,:);
            board(i,:)='  ';
            history{end+1}=board;
            addon;
            history=saveHist;
            board=saveBoard;
         end
      elseif bareBoard(i)=='l'
         if i==blank+1 || i==blank+2
            saveBoard=board;
            saveHist=history;
            board(blank,:)=board(i,:);
            board(i,:)='  ';
            history{end+1}=board;
            addon;
            history=saveHist;
            board=saveBoard;
         end         
      end
    end
  end
end


finds two symmetric ways of accomplishing the task, one starting on the left and one on the right. The number of moves in each is 24, so we show 25 states, starting with the original state and ending with the final state.  The markers are labelled with their direction of travel, with the rightward ones initially on the left labelled 'r' and the leftward ones initially on the right labelled 'l'.  Each set of four is numbered 1-4 from left to right.

White pieces move right and are labeled 'r'.
Black pieces move left and are labeled 'l'.

 
    25           25 states (0 through 24)
    
    
rrrr llll        initial state
1234 1234
 
rrr rllll        r4 moves forward
123 41234
 
rrrlr lll        l1 jumps him
12314 234
 
rrrlrl ll        l2 moves forward
123142 34
 
rrrl lrll        r4 jumps him
1231 2434
 
rr lrlrll        r3 jumps l1
12 132434
 
r rlrlrll        r2 moves forward
1 2132434
 
rlr rlrll        l1 jumps him
112 32434
 
rlrlr rll        l2 jumps r3
11223 434
 
rlrlrlr l        l3 jumps r4
1122334 4
 
rlrlrlrl         l4 moves forward
11223344 
 
rlrlrl lr        r4 jumps him
112233 44
 
rlrl lrlr        r3 jumps l3
1122 3344
 
rl lrlrlr        r2 jumps l2
11 223344
 
 lrlrlrlr        r1 jumps l1
 11223344
 
l rlrlrlr        l1 moves forward
1 1223344
 
llr rlrlr        l2 jumps r1
121 23344
 
llrlr rlr        l3 jumps r2
12132 344
 
llrlrlr r        l4 jumps r3
1213243 4
 
llrlrl rr        r3 moves forward
121324 34
 
llrl lrrr        r2 jumps l4
1213 4234
 
ll lrlrrr        r1 jumps l3
12 314234
 
lll rlrrr        l3 moves forward
123 14234
 
llllr rrr        l4 jumps r1
12341 234
 
llll rrrr        r1 moves forward
1234 1234


and starting move in the other direction:
 
 
    25
rrrr llll
1234 1234
 
rrrrl lll
12341 234
 
rrr lrlll
123 14234
 
rr rlrlll
12 314234
 
rrlr rlll
1213 4234
 
rrlrlr ll
121324 34
 
rrlrlrl l
1213243 4
 
rrlrl lrl
12132 344
 
rrl lrlrl
121 23344
 
r lrlrlrl
1 1223344
 
 rlrlrlrl
 11223344
 
lr rlrlrl
11 223344
 
lrlr rlrl
1122 3344
 
lrlrlr rl
112233 44
 
lrlrlrlr 
11223344 
 
lrlrlrl r
1122334 4
 
lrlrl lrr
11223 434
 
lrl lrlrr
112 32434
 
l lrlrlrr
1 2132434
 
ll rlrlrr
12 132434
 
lllr rlrr
1231 2434
 
lllrlr rr
123142 34
 
lllrl rrr
12314 234
 
lll lrrrr
123 41234
 
llll rrrr
1234 1234
 

  Posted by Charlie on 2022-11-16 09:36:29
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 (3)
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