Swapping Monkeys

Five monkeys in a circus are sitting in the following order:

The ringmaster wants to reverse their order, but only by swapping the positions of two monkeys at a time.

This is one way, where two swaps take place:

1
2
Swap A and E: E B C D A
Swap B and D: E D C B A

Another possible way takes exactly four swaps:

1
2
3
4
Swap A and E: E B C D A
Swap C and D: E B D C A
Swap B and D: E D B C A
Swap B and C: E D C B A

Is it possible to do this in exactly three swaps?

Yes No

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

13 solutions

Jason Dyer Staff
Apr 26, 2018

(This problem should be familiar with those who know group theory and know the terminology in Thomas's answer. However, the proof regarding odd/even parity of permutations can be a little technical. This is a non-technical presentation and includes the most intuitive proof of parity that I know of.)

First, let's consider the problem with 3 monkeys. Here is a chart of every possibility. If one sequence can reach another by a single swap, they are connected with a line.

By swapping, you can only flip between the bottom and top rows.

Move 1 (on bottom, move number is odd) -> Move 2 (on top, move number is even) -> Move 3 (on bottom, move number is odd) -> etc.

That means any sequence on the top row is reachable by an even number of moves and any sequence on the bottom or is reachable by an odd number of moves.

The same principle applies to this kind of operation (called a permutation) in general - if a sequence can be reached by an even number of moves, it can't be reached by an odd number of moves, and vice versa.

The general explanation is a little more involved, but below.


Write you starting sequence ABCDE, and then below write your first swap. Draw curves connecting each pair of letters, being careful so that any intersection only happens between two curves at one time. Keep going like this for each step, writing ABCDE on top and your new sequence on the bottom.

Note something very important: between each step, you can only add or subtract an odd number of intersections in one move . (See an example below where ABCDE gets changed to DBCAE.)

This is because between the two letters that get swapped exactly 1 intersection is added or removed, and then any curves in between the swap overlap at exactly 2 intersections, so any extra points added or subtracted must be done 2 at a time; this results in an odd intersection change number like 1 + 2 + 2 2 + 2 = 5. 1 + 2 + 2 - 2 + 2 = 5 .

Since the sequence starts with an even number of intersections (0) each step of adding or subtracting an odd number of intersections swaps the number of intersections between odd and even.

(move 0) even number of intersections -> (move 1) odd number of intersections -> (move 2) even number of intersections -> (move 3) odd etc.

This means if we have a particular permutation where the final picture has an odd number of intersections, it will take an odd number of moves to get there. If we have a picture with an even number of intersections, it will take an even number of moves to get there.

In the case of our problem, we have a solution with an even number of intersections, so any solution at all will require an even number of moves.

great explanation!, just a detail, in the third and last drawings, you have the A, C and E curves intersecting at a single point, it should be 10 intersections in total, not 8

Jose Fernandez Goycoolea - 3 years, 1 month ago

Log in to reply

fixed it, thanks!

Jason Dyer Staff - 3 years, 1 month ago

In your explanation, you have written : "let's consider the problem with 3 monkeys. Here is a chart of every possibility." I am unable to interpret this thing. If "problem with 3 monkeys, means swapping 3 monkeys", how does the chart depict it, can you please relate to it ?

Tarun Khullar - 3 years, 1 month ago

Log in to reply

I replaced the wrong image fixing the other problem - I'll have to get to it on Monday.

Jason Dyer Staff - 3 years, 1 month ago

Respected Sir and everyone , Please excuse me for posting this comment . Rather than saying that this is a comment this a burning issue in my heart . Please take it seriously .

Note : This post is regarding the Easy section of this problems of week .

I have a dream getting 100 or more up votes for an individual solution . I wrote a solution for the question water shadows (which is adjacent to this question) 6 days ago (on 21 April) . When I wrote the solution I thought it is a good one and will definitely accomplish my dream .

I am extremely happy when I saw that the question is in one of the problems of the week . I thought I am nearer to my dream because nobody posted any solution at that time expect me to this question and my solution is a clear and good one . But after these four days I am extremely sad because even more than 11,000 people solved that question only 83 people are discussing solutions . As a result at present I am only left now with 45 up votes . Although my solution deserves more than 100 up votes due silly reasons it is unable to accomplish my dream .

At first when I solved this question (infinite squares) on Monday morning I solved in the manner you did . I thought to post the solution but when I saw you have already posted the same solution (and now you got 299 up votes) . But I didn't worry at that time because I had hope that my solution to water shadows question will definitely cross 100 up votes .

Once see the up votes to the top solutions for the 5 questions of the problems of this week and see how odd it looks :

Infinite squares - Jason Dyer - 349 up votes

Water shadows - Ram Mohith - 57 up votes (see how odd it looks)

Third problem - Zain Majumder - 167 up votes

Fourth problem - Jeremy Galvagni - 129 up votes

Fifth problem - Micheal Mendrin - 250 upvotes

My point is that please try to discuss solutions to every question you solved and try to up vote the solution you admire as much as possible . If you do that many people like me will acheive what they deserve .

Please try to understand my problem .

Ram Mohith - 3 years, 1 month ago

Log in to reply

The science problems aren't as popular as the math, so they just won't get as many readers. That means there won't be as many people to upvote the solution.

Don't worry too much about it! (If you really need to compare, check against science problems in previous weeks)

Also, the very first problem will always have at least triple the audience (due to it occurring in email).

Jason Dyer Staff - 3 years, 1 month ago

That was cool af, thanks for taking the time to write that out :)

B Utt - 3 years, 1 month ago

The two examples provided show that the permutation (1,2,3,4,5) \rightarrow (5,4,3,2,1) is pair .

The sign of a permutation σ \sigma ( ( denoted ϵ ( σ ) ) \epsilon(\sigma)) is defined as

ϵ ( σ ) = ( 1 ) inv ( σ ) , \displaystyle \epsilon(\sigma) = (-1)^{\text{inv}(\sigma)},

where inv ( σ ) \text{inv}(\sigma) is the number of inversions of σ , \sigma, or the number of pairs ( a , b ) (a,b) with a , b { 1 , 2 , , n } a,b \in \{1,2,\ldots,n\} such that σ ( a ) > σ ( b ) , a < b \sigma(a)>\sigma(b), a<b .

Therefore the permutation cannot be computed using 3 inversions.

more details

yeah....i guess i was a little overconfident

Kirithik Gopi - 3 years, 1 month ago

hey it is possible first do it E and D then do it with A and D then with E and B

Olevester Joram - 3 years, 1 month ago

Log in to reply

Nope, you end up with "EDCAB", not with "EDCBA"

Thomas Lesgourgues - 3 years, 1 month ago

Log in to reply

sorry my typing mistake it is A and D then B and E

Olevester Joram - 3 years, 1 month ago

Log in to reply

@Olevester Joram D and E are the wrong way round.

Joseph Newton - 3 years, 1 month ago

This assumes the thing we are trying to prove, i. e. that three inversions cannot give the same configuration as two inversions

Matt McNabb - 3 years, 1 month ago

4 monkeys alone must be moved requiring if you imagine moving a monkey into the right place you can add 1. We need an addition of 5. In three moves this means that two of them must put two monkeys in the right place and one of them must only change one. There is no way to swap two monkeys such that one goes into the right place, without first swapping a pair of monkeys so that none are moved into the right place.

How can we rigorously show that the number of swaps must be even?

Agnishom Chattopadhyay - 3 years, 2 months ago

Log in to reply

After a swap operation, the number of inversions in the array modulo 2 will always toggle. This is provable using mod 2 parity and odd-even case analysis.

sidhant bansal - 3 years, 1 month ago

Log in to reply

More rigorous argument is https://en.wikipedia.org/wiki/Alternating_group using the even permutation argument.

sidhant bansal - 2 years, 8 months ago

Log in to reply

@Sidhant Bansal Seems like you have read up on Group Theory in the last few months. Good job!

Agnishom Chattopadhyay - 2 years, 8 months ago

i support u on that

Olevester Joram - 3 years, 1 month ago

What about 3 monkeys? 2 must be moved but this can be done in an odd number of moves. One.

I think you mean the number of pairs to be swapped is even.

Jeremy Galvagni - 3 years, 1 month ago

A and b, b and d, a and e.

David Hubbs - 3 years, 1 month ago

Log in to reply

D and E are the wrong way round.

Joseph Newton - 3 years, 1 month ago

hey it is possible first do it E and D then do it with A and D then with E and B

Olevester Joram - 3 years, 1 month ago

Log in to reply

D and E are the wrong way round.

Joseph Newton - 3 years, 1 month ago

We can represent each permutation by its corresponding permutation matrix (having only zeroes except for exactly one 1 1 in each column and each row), for example the wanted monkeys permutation ( A , B , C , D , E ) ( E , D , C , B , A ) (A,B,C,D,E)\longrightarrow (E,D,C,B,A) is given by the matrix P P that reorder the monkey's vector throw multiplication:

[ 1 1 1 1 1 ] [ A B C D E ] = [ E D C B A ] \left[\begin{array}{ccccc} &&&&1\\ &&&1&\\&&1&&\\&1&&&\\1&&&&\end{array}\right] \left[\begin{array}{c}A\\B\\C\\D\\E\end{array}\right] =\left[\begin{array}{c}E\\D\\C\\B\\A\end{array}\right]

In this language, the problem consists in rewriting the matrix P P as a multiplication of transposition matrices (that only swap two letters), the first example given before is:

[ 1 1 1 1 1 ] [ 1 1 1 1 1 ] [ A B C D E ] = [ 1 1 1 1 1 ] [ E B C D A ] = [ E D C B A ] \left[\begin{array}{ccccc}1&&&&\\&&&1&\\&&1&&\\&1&&&\\&&&&1\end{array}\right] \left[\begin{array}{ccccc}&&&&1\\&1&&&\\&&1&&\\&&&1&\\1&&&&\end{array}\right] \left[\begin{array}{c}A\\B\\C\\D\\E\end{array}\right] =\left[\begin{array}{ccccc}1&&&&\\&&&1&\\&&1&&\\&1&&&\\&&&&1\end{array}\right] \left[\begin{array}{c}E\\B\\C\\D\\A\end{array}\right] =\left[\begin{array}{c}E\\D\\C\\B\\A\end{array}\right]

Now suppose that this could be done with three transpositions P = T 1 T 2 T 3 P=T_1T_2T_3 then we would have

1 = det ( P ) = det ( T 1 T 2 T 3 ) = det ( T 1 ) det ( T 2 ) det ( T 3 ) = ( 1 ) 3 = 1 1=\det(P)=\det(T_1T_2T_3)=\det(T_1)\det(T_2)\det(T_3)=(-1)^3=-1

which clearly can't be true. Can you see why det ( T ) = 1 \det(T)=-1 for any transposition matrix?

This is my favourite answer. I didnt get any other answer. Thank you

Manoj 420 - 3 years, 1 month ago
Eayan Biswas
Apr 22, 2018

For 3 swaps the number of monkeys must be a multiple of 3.

This is not true. Three swaps works if and only if the number of monkeys is 2, 3, 6, or 7. Note 2 and 7 are not multiples of 3, and no higher multiple of 3 works.

Brian Moehring - 3 years, 1 month ago

hey it is possible first do it E and D then do it with A and E then with D and B

Olevester Joram - 3 years, 1 month ago

Log in to reply

Nope that ends up as EDCAB

James Felling - 3 years, 1 month ago

Then for 2 swaps the number of monkeys must be a multiple of 2 which is not the case here. But 2 swaps situation is possible

Mohit Mohandas - 3 years, 1 month ago
Peter Macgregor
Apr 23, 2018

Any permutation can be achieved by making a sequence of pairwise swaps. It is quite well known that the permutations of a given set fall into two classes:- those requiring an even number of swaps (and which cannot be done with an odd number of swaps), and those requiring an odd number of swaps (and which cannot be done with an even number of swaps).

Since the question shows us explicitly that the required permutation can be done with an even number of swaps we know immediately that it cannot be done with an odd number of swaps. In particular it cannot be done with three swaps \boxed{\text{it cannot be done with three swaps}}

Here is a nice intuitive explanation of the parity property of permutations.

hey it is possible first do it E and D then do it with A and E then with D and B

Olevester Joram - 3 years, 1 month ago

Log in to reply

Hi Joram,

here is what happens with your three swaps...

ABCDE -> ABCED -> EBCAD -> EDCAB

You can see that you need one more swap (making an even number) to reverse the order completely.

Peter Macgregor - 3 years, 1 month ago
Erica Phillips
Apr 27, 2018

The give order is :A,B,C,D,E The required order:E,D,C,B,A In both the cases C remains in the middle(2 positions far from the right and 2 potions far from the left). So in 3 swaps this arrangement is impossible because we need to first take C and swap with some other position and then swap it back again with the correct position hence twice the work ,therefore this work takes place for 2n times and three times swapping doesn't hold a stand.

Karl Festersen
Apr 25, 2018

Monkey C has to stay in the middle, so there are 4 left who "take" two of three swaps. Now the order is reversed and any third swap would break it.

R Mathe
May 6, 2018

No. One can prove in algebra, that for all n N + n\in\mathbb{N}^{+} , that

π : S n ( Z / 2 Z , + ) \pi:S_{n}\longrightarrow (\mathbb{Z}/2\mathbb{Z},+)

given by π ( σ ) = m o d ( L , 2 ) \pi(\sigma)=\mod(L,2) where L = L= length of a decomposition of σ \sigma into 2-swaps, is well-defined (and necessarily an homomorphism). Here we have an element (the permutation that reverses the order) in S 5 S_{5} and we are counting up the length of a decomposition into 2-swaps: by the above, this is necessarily always even.

Haoran Wang
Apr 29, 2018

The fastest move is 2 steps. And if we want to let it slower, we only can add C move into it, but fastest move C to another position and back need 2 steps, 2+2=4, so we can't do it in 3 steps. (Maybe?)

Marcus Campbell
Apr 27, 2018

I just thought, "The examples only show an even number of moves. There are an even number of monkeys that have to move, therefore, there can't be an odd number of moves to achieve the desired objective." Is this wrong?

Consider the following numeric function with 5 arguments:

f ( X 1 , X 2 , X 3 , X 4 , X 5 ) = ( X 1 X 2 ) ( X 1 X 3 ) ( X 1 X 4 ) ( X 1 X 5 ) ( X 2 X 3 ) ( X 2 X 4 ) ( X 2 X 5 ) ( X 3 X 4 ) ( X 3 X 5 ) ( X 4 X 5 ) f(X_1,X_2,X_3,X_4,X_5)=(X_1-X_2)(X_1-X_3)(X_1-X_4)(X_1-X_5)(X_2-X_3)(X_2-X_4)(X_2-X_5)(X_3-X_4)(X_3-X_5)(X_4-X_5)

Every two by two combination of the arguments are presented in the form of a unique difference, factor to the product. If all the arguments takes different numeric values, the result of the function will be different from zero, positive or negative. The signal of this value, changes when the values ( x x and y y ) of two arbitrary arguments ( X x X_x and X y X_y ) are swapped. This happens because:

  • the single factor ( X x X y ) (X_x - X_y) changes signal (since ( x y ) = ( y x ) (x-y)=-(y-x) ).
  • the products ( X x X z ) × ( X y X z ) (X_x - X_z)\times(X_y - X_z) stays unchanged (since ( x z ) × ( y z ) = ( y z ) × ( x z ) (x-z)\times(y-z)=(y-z)\times(x-z) ).
  • the products ( X x X z ) × ( X z X y ) (X_x - X_z)\times(X_z - X_y) stays unchanged (since ( x z ) × ( z y ) = ( y z ) × ( z x ) (x-z)\times(z-y)=(y-z)\times(z-x) ).
  • the products ( X z X x ) × ( X z X y ) (X_z - X_x)\times(X_z - X_y) stays unchanged (since ( z x ) × ( z y ) = ( z y ) × ( z x ) (z-x)\times(z-y)=(z-y)\times(z-x) ).
  • the other factors ( X z X w ) (X_z - X_w) stays unchanged (since, as you must have guessed, z z and w w means values for non-exchanged arguments).
  • when we exclude from the product that constitutes our function, all the terms like the previous ones, no other term remains.

A function defines an order over its arguments. I show here a function that changes its signal when we exchange an argument value for another, being numerical monkeys or otherwise. Another exchange and the signal returns to the original. An even number of exchanges leaves the function result invariant, an odd number flips its signal. Because a numerical result different from zero cannot be both positive and negative, a permutation achievable by an odd number of swaps cannot be reached by an even number, and vice-versa. This conclusion is not dependent on the number of monkeys.

Since we already verified that we can reverse the order of our monkeys by doing an even number of swaps, this excludes the possibility of doing it using an odd number of swaps, like three.

Corwin Silverman
Apr 26, 2018

Given that the permutation can be performed using two swaps, the permutation is an element of the group A5. If we assume that the permutation can be performed using three swaps, then the permutation would not be an element of A5.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...