Francois arranged 40 coins in a line from left to right on the table with each coin showing heads. Francois repeatedly chooses two coins, such that the leftmost coin (of the two) shows heads and flips over both the coins. What is the most number of times Francois can flip a pair of coins before he is unable to flip any more coins?
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.
We can label the coins with the numbers 0,1,2,3,4,...,n-1 from the right to the left. If a coin shows head its value is 0, else if a coin shows cross its value is equal to its label. The sum of all coin's values increases in each flips (in fact in each step there is a coin on the left that shows head). The starting value of this sum is 0. The maximum value is 0+1+2+...+n-1 = n(n-1)/2. So we can do maximum n(n-1)/2 flips. The algorythm to obtain exactly n(n-1)/2 flips is just shown.
Log in to reply
Awesome, that explains the "shortcut solution" someone else posted too.
Beautiful solution thanks
i did like this too, but it's too hard to write down though.
Brilliantly done. Most people would have seen the pattern but writing a proof would have been very hard.
I tried recursion. It gives the answer by pattern recognition but proof seems to be hard to come by.
Log in to reply
Well this is how I saw it:
For n = 2, you go HH to TT, one step, simple. For n = 3, you add another H to the right. So now you have HTT. Then you essentially move that H to the right most space, adding two more steps. For n = 4, you add yet another H, doing the same thing (this time, adding 3 more flips since there are 3 more spaces). From a conceptual standpoint, this is WHY that when you have n coins, the answer is the n-1th triangle number.
Actually using your method we can come up with a recursion proof as well.
Log in to reply
Yeah - you can remove the rightmost two coins and then move all other coins right twice , then you forget about the left-most two spaces and start again. It's fairly similar.
An extension to this problem could be: how many ways are their to do n ( n − 1 ) / 2 flips?
Python could deal with that handily for our n = 4 0 case, but I'm wondering if there's a closed-form expression. (I suspect there isn't, based on thinking about it for a little while, but I figured I'd throw it out to anyone who might like to try.)
Here's an informal solution based on pattern-matching. We'll simulate the optimal (longest) sequence of coin flips for 2, 3, 4 and 5 coins based on the principle that we always want to pick the rightmost heads and the leftmost tails, since once there are no heads to the left of a tails it's "stuck".
H H
T T -> 2 coins, 1 flip
H H H
H T T
T H T
T T H -> 3 coins, 3 flips
H H H H
H H T T
H T H T
H T T H
T H T H
T T H H
T T T T -> 4 coins, 6 flips
H H H H H
H H H T T
H H T H T
H H T T H
H T H T H
H T T H H
H T T T T
T H T T T
T T H T T
T T T H T
T T T T H -> 5 coins, 10 flips
The pattern seems clear: f ( n ) = 2 n ( n − 1 ) , and f ( 4 0 ) = 7 8 0 . Not a proof of course but sometimes a good guess is good enough.
Why is a guess voted second top? That's kind of disappointing to me...
You could have at least mentioned (or noticed?) that when you go n = k to n = k + 1, you essentially just add an H to the left, and then move that H all the way to the right. For example
HH
TT
then
HTT
THT
TTH
then
HTTH
THTH
TTHH
TTTT
etc.
Great. I have the same solution
We prove that the answer is 1 + 2 + . . . + 3 9 = 7 8 0 .
Clearly we can manage this, by flipping the rightmost pair, then the rightmost two pairs from left to right, then the rightmost three pairs from left to right, and so on (so flip pairs 39, 38, 39, 37, 38, 39, ...).
Conversely, we prove that the pair whose left coin is coin n can be flipped at most n times (giving rise to an upper bound of the sum above). We prove this inductively - clearly pair 1 can be flipped only once, and pair n − 1 must be flipped between each flip of pair n , so there can be at most one more flip of pair n , as required.
It uses simple Combination. We have 40 coins and choose 2 coins. So, ( 4 0 2 ) = 2 ! ( 4 0 − 2 ) ! 4 0 ! = 780
I suggest you reread the problem. Unfortunately, this gives the correct answer.
Log in to reply
It'd be interesting to find a way of looking at the problem so that this answer makes sense.
Log in to reply
Yes. I don't see how that could be done, but it is interesting.
Log in to reply
@Daniel Chiu – Unluckily, that is expected. The correct answer for n coins is 2 n ( n − 1 ) , which is also equal to ( 2 n ) .
@Daniel Chiu – Tomas D. explained it elsewhere on the thread.
Number all the squares 0 , 1 , 2 , . . . , 3 9 from right to left. Consider the sum of all numbers that have tails on them. It starts off at 0 , and each possible move increases is sum. (In my solution the moves I use increase the sum by exactly 1 ). When all the heads are gone the sum is 0 + 1 + 2 + . . . + 3 9 = 4 0 C 2 , so this is the maximum number of possible moves.
I'm a bit surprised that a totally wrong statement still leads to the read answer
Its just an illogical solution having the same answer by coincidence (due to the imposed conditions).
Log in to reply
The coincidence actually holds for all positive integers!
Log in to reply
If somebody would kindly prove it in these comments, or even better, in the discussions. It would be great. If it holds true, then it's surely an interesting topic.
Log in to reply
@Arnab Animesh Das – It does hold true. The fact that for n coins the result is 2 n ( n − 1 ) has been proved in James A.'s solution. But again, note that 2 n ( n − 1 ) = ( 2 n )
Simple Combination, That`s great!
Assuming we can flip a maximum of N times for A coins. So after flipping N times the sequence would be TTTTTTTTT (A-1 times) with H or T in end.
For A+1 coins after flipping pair of coins N times we get to a situation like H TTTTTTT (H/T). We can make another A flips in this sequence by flipping the coins (1,2),(2,3),(3,4)...(A,A+1) in order. so if we can flip N times for A coins we can flip N+A times for A+1 coins.
A=2 N=1
A=3 N=3
A=4 N=6 so
A=40 N=39*40/2=780
Let a n be the maximum number of flips possible with n coins. Note that a 2 = 1 , because when there are 2 coins, a single operation exhausts all the coins showing heads. Now we shall determine a relationship between a n + 1 and a n .
Label the n + 1 coins 1 , 2 , ⋯ , n + 1 from left to right. We first ignore coin 1 , and consider the set { 2 , 3 , . . . , n + 1 } . We can flip these coins in at most a n ways. Note that after these coins are flipped, coin 1 will show head, and all coins from the set { 2 , 3 , . . . , n } will show tails. The ( n + 1 ) t h coin will either show head or tails (depending on the parity of n ). After we have applied the operation a n times on the set { 2 , 3 , . . . , n + 1 } , we take the set { 1 , 2 } and flip them. Then coin 2 will show heads, and we do the same for 3 . We then keep on doing this until we reach the set ( n , n + 1 ) . Note that this is the optimal strategy here, since this keeps the left-most coin showing heads for the longest number of operations. Hence we obtain the recurrence relation a n + 1 = a n + n . We can easily solve this recurrence relation using the fact that a 2 = 1 : a n = 1 + 2 + . . . + ( n − 1 ) = 2 n ( n − 1 ) At n = 4 0 , it equals to 2 3 9 ∗ 4 0 = 7 8 0 .
Assign each coin a value equal to its distance from the rightmost coin. (Thus, for 40 coins, the values assigned will be 39,...,0.) The problem specifies that the setup is all-coins-showing-heads, but we can prove by induction that for any setup the maximum number of flips that can be performed is equal to the sum of the values of all coins that show heads, which we designate V .
First note that it is irrelevant whether the rightmost coin shows heads or tails (i.e. it doesn't affect the value of V and it will never affect whether a particular flip is legal or not), so WOLOG we can assume it shows tails. (Alternately put, we can replace it with a two-tailed coin.)
Now V = 0 if and only if all coins show tails, in which case no flips are possible. For the inductive step, V > 0 means that one or more coins (not the rightmost one) show heads. Francois can choose the rightmost out of those coins, together with the coin (showing tails) to its immediate right. Then the new sum of head-values is V − 1 as desired, which completes the proof (since any other flip he could choose would also decrease the sum by at least 1 ).
Let c ( n ) be the number of turns of n coins when only the left most coin is heads and all the other coins are tails with the right most coin being optionally heads or tails (does not matter). Then c ( 1 ) = 0 , c ( 2 ) = 1 . c ( n ) = 1 + c ( n − 1 ) . This is because in the c(n) configuration, only the left most coin is heads and all the others are tails and in choosing the two coins, the most number of turns is obtained when we choose the left most coin (forced) and the coin immediately right of it. Any other choice of the second coin will result in lesser number of overall turns. But in the c ( n ) configuration, when we flip the coin immediately right of the left most coin, the configuration of the second to last from the left coins is exactly the c ( n − 1 ) configuration.
Let t ( n ) be the total number of turns when we start with all heads. Then t ( n ) = c ( n ) + c ( n − 1 ) . . + c ( 1 ) . Applying c ( n ) = 1 + c ( n − 1 ) recursively, we get, t ( n ) = ( n − 1 ) + ( n − 2 ) + . . + 1 . So t ( n ) = 2 ( n − 1 ) n . For n = 4 0 , we have t ( n ) = 7 8 0 .
Problem Loading...
Note Loading...
Set Loading...
Let's imagine we have 40 spaces and each space could contain a head. Instead of tails I'll use blank space , this makes the language a bit simpler.
The effect of one of Francois's flip is either: (a) Remove two heads, or (b) Move a head to the right.
If a maximal sequence contains a move of type (a), then it must be removing two heads from the two right-hand spaces. Because if it were removing any other two heads, we could replace that by the longer sequence of moving the heads to the right and then removing them.
If a maximal sequence contains a move of type (b) then it must be moving a head one space to the right. Otherwise we could replace that move by a series of moves of a head one space to the right.
So the longest possible sequence is, starting from n = 0
Step n part 1: Move the right-most two heads to the far right
Step n part 2: Remove two heads from the right
and we repeat this until all heads are gone.
Now, part 1 requires 4 n moves: we're moving two coins and each coin has to go as many spaces over as coins we've removed so far.
Part 2 is just 1 move of course.
And we make 2 0 steps in total because each step removes 2 coins and there are 2 × 2 0 coins to remove.
So the value we want is 2 0 × 1 + 4 ( 0 + 1 + 2 + . . . + 1 9 ) = 2 0 + 4 × 1 9 0 = 7 8 0