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

 Trading Places 2 (Posted on 2022-11-16)
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.)
 computer solution (spoiler) | Comment 1 of 7
clc
global history

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

history={board};

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;
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;
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 state1234 1234 rrr rllll        r4 moves forward123 41234 rrrlr lll        l1 jumps him12314 234 rrrlrl ll        l2 moves forward123142 34 rrrl lrll        r4 jumps him1231 2434 rr lrlrll        r3 jumps l112 132434 r rlrlrll        r2 moves forward1 2132434 rlr rlrll        l1 jumps him112 32434 rlrlr rll        l2 jumps r311223 434 rlrlrlr l        l3 jumps r41122334 4 rlrlrlrl         l4 moves forward11223344  rlrlrl lr        r4 jumps him112233 44 rlrl lrlr        r3 jumps l31122 3344 rl lrlrlr        r2 jumps l211 223344  lrlrlrlr        r1 jumps l1 11223344 l rlrlrlr        l1 moves forward1 1223344 llr rlrlr        l2 jumps r1121 23344 llrlr rlr        l3 jumps r212132 344 llrlrlr r        l4 jumps r31213243 4 llrlrl rr        r3 moves forward121324 34 llrl lrrr        r2 jumps l41213 4234 ll lrlrrr        r1 jumps l312 314234 lll rlrrr        l3 moves forward123 14234 llllr rrr        l4 jumps r112341 234 llll rrrr        r1 moves forward1234 1234`

and starting move in the other direction:

`     25rrrr llll1234 1234 rrrrl lll12341 234 rrr lrlll123 14234 rr rlrlll12 314234 rrlr rlll1213 4234 rrlrlr ll121324 34 rrlrlrl l1213243 4 rrlrl lrl12132 344 rrl lrlrl121 23344 r lrlrlrl1 1223344  rlrlrlrl 11223344 lr rlrlrl11 223344 lrlr rlrl1122 3344 lrlrlr rl112233 44 lrlrlrlr 11223344  lrlrlrl r1122334 4 lrlrl lrr11223 434 lrl lrlrr112 32434 l lrlrlrr1 2132434 ll rlrlrr12 132434 lllr rlrr1231 2434 lllrlr rr123142 34 lllrl rrr12314 234 lll lrrrr123 41234 llll rrrr1234 1234`

 Posted by Charlie on 2022-11-16 09:36:29

 Search: Search body:
Forums (0)