Splitting Piles

You are given a set of cards arranged in a line. Each card is either black \color{#333333}{\text{black}} or red \color{#D61F06}{\text{red}} . You may divide the cards into two parts by picking a line before or after the whole cards (so that a part can contain 0 cards), or somewhere between two cards.

No matter how many cards are arranged in whatever manner, can you always ensure the number of black \color{#333333}{\text{black}} cards in the left part is exactly the same as the number of red \color{#D61F06}{\text{red}} cards in the right part?


An example split that fulfills the condition is shown below.

There is 1 \(\color{black}{\text{black}}\) card in the left part and 1 \(\color{red}{\text{red}}\) card in the right part There is 1 black \color{#333333}{\text{black}} card in the left part and 1 red \color{#D61F06}{\text{red}} card in the right part

Yes, always No, not necessarily

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.

8 solutions

Zain Majumder
Oct 22, 2017

Imagine you divide the cards randomly, and there are B B black cards on the left, and R R red cards on the right. If B < R B < R , move the division to the right one space. One card will be taken away from the red side and brought to the black side.

If this card is black, then B B increases by 1 1 , while R R remains unaffected. If this card is red, then R R decreases by 1 1 , while B B remains unaffected. Either way, B B and R R are now closer together by exactly 1 1 card. If this process is repeated, B B and R R will eventually be equal.

If B > R B > R , move the division left instead. The same logic applies, so it is always possible to divide the cards such that B = R B = R .

Moderator note:

While this solution doesn't explicitly need to mention them (as they are covered by following the steps shown) it's worth highlighting the cases with all red cards and all black cards.

With all red cards, the dividing line can be put to the far right. Then there are 0 black cards to the left (since the line is all red) and 0 red cards to the right (since nothing is to the right).

With all black cards, the dividing line can be put to the far left, with a similar resolution.

This problem only works on the condition that there is at least one red and one black card in the selection. Given a truly random selection of cards there is a chance that all cards will be one color and that chance increases with the less cards there are in the line. Therefore given the conditions of the problem the supposed correct answer is incorrect.

George Watt - 3 years, 7 months ago

Log in to reply

@George Watt , The question allows you to put the line on either edge so that there are zero cards to the right or to the left of the line. If the cards are all Red, put the line to the Right so there are zero Black to the left of it and zero Red to the right of it.

Mark Monnin - 3 years, 7 months ago

The problem specifically stated that the divider may be on the very ends. In the case all cards are one color, the divider will need to be on one of the ends, but it will still work.

Zain Majumder - 3 years, 7 months ago

Log in to reply

The question should have been clearer by saying in the last paragraph, "can you ensure, BY MOVING THE LINE, that the number of black cards [etc...]"

This is because I misinterpreted it as saying "is it possible to have an arrangement where the number of blacks on one side is different from the number of reds on the other?" "So that a part can contain 0 cards", so obviously if you move the line to the end in the example shown, there are 0 on one side and non-zero on the others, so it is not necessarily true.

Erik Bentham - 3 years, 7 months ago

it actually said that no part can contain 0 cards, so the answer is incorrect.

gh dgfhdgf - 3 years, 5 months ago

What if there is only 1 red card (day), positioned at one of the edges?

Guilherme Finkelfarb Lichand - 3 years, 7 months ago

Log in to reply

@Guilherme Finkelfarb Lichand If there is one red card and no other cards, put the line to the right of it. Zero Black To The Left = Zero Red To The Right. If there is one red card on the left edge with one or more black cards to its right, put the line to the right of the red card. Zero Black To The Left = Zero Red To The Right. If there is one red card on the right edge with one or more black cards to its left, put the line to the right of the left-most black card. One Black To The Left = One Red To The Right.

Mark Monnin - 3 years, 7 months ago

Log in to reply

Got it - thank you. I see the issue is rather with zero.

Guilherme Finkelfarb Lichand - 3 years, 7 months ago

It could be worded better but, it is a nice simple problem.

Tim Rammel - 3 years, 5 months ago

"If this process is repeated, B and R will eventually be equal." - but how do you know that you won't reach the end of the row of cards before this happens?

The proof is essentially right but needs tightening up somewhat.

Paul Cockburn - 2 years, 8 months ago
Arjen Vreugdenhil
Oct 23, 2017

Proof by induction

Any arrangement of cards may be constructed in a finite number of steps, by starting with one card, and adding cards to the right, one by one. We will show that it always possible to maintain the condition during the building process.

Base step : With one card, if it is black draw the line to the left; if it is red, draw the line to the right.

Induction step : Suppose the situation is part 1 x black part 2 x red . \underbrace{\text{part 1}}_{x\ \text{black}}\ \|\ \underbrace{\text{part 2}}_{x\ \text{red}}. We add a card on the right side. There are three cases to consider.

Case I. The new card is black: there is no need to move the line. part 1 x black part 2 x red B . \underbrace{\text{part 1}}_{x\ \text{black}}\ \|\ \underbrace{\text{part 2}}_{x\ \text{red}}\ \ B.

Case II. The new card is red, and part 2 is either empty or starts with a red card. In this case, move the line one step to the right. There will still be x x black cards on the left and x x red cards on the right. part 1 x black R rest of part 2 x 1 red R . \underbrace{\text{part 1}}_{x\ \text{black}}\ \ R\ \ \| \ \underbrace{\text{rest of part 2}}_{x-1\ \text{red}}\ \ R.

Case III. The new card is red, and part 2 starts with a black card. In this case, move the line one step to the right. There will be x + 1 x+1 black cards on the left and x + 1 x+1 red cards on the right. part 1 x black B rest of part 2 x red R . \underbrace{\text{part 1}}_{x\ \text{black}}\ \ B\ \ \| \ \underbrace{\text{rest of part 2}}_{x\ \text{red}}\ \ R.

Excellent!

Jiayun Zhao - 3 years, 7 months ago
Stephen Brown
Oct 8, 2017

Count cards one by one off the top of the pile; if the magician has x red cards and his assistant has y black cards with x>y, then either: 1. He loses a red card and his assistant gains a red card, making x-1 red cards and y black cards, or: 2. He loses a black card and his assistant gains a black card, making x red cards and y+1 black cards. In either case, we see that we increment x toward y by 1, and eventually can make them equal.

When I answered this question, I understood it to mean that you would need to have an equal amount of black cards on the left as red cards on the right no matter where a division was placed in the line. However, I now understand it to say that you can choose one division for each given set of cards. That being the case, yes of course.

Btw, if all the cards are red, just choose your division all the way to the right of all the cards. Then there are no black cards left of the line and no red cards right of it.

Danielle Doty - 3 years, 7 months ago

The wording of this problem is not clear and misleading . I do not like it at all.

samer shoukry kossa - 3 years, 7 months ago

Yes, this is an elegant observation indeed.

Agnishom Chattopadhyay - 3 years, 8 months ago

I am not grasping something (or disagree with the answer).. The starting condition is: "You are given a set of cards arranged in a line. Each card is either black or red". There is nothing that says what the number of cards in the set are, or what the mixture of black & red will be. Suppose there are six cards as illustrated in the set, and all six cards are black. The answer should be "No, not necessarily".

Robert Beach - 3 years, 7 months ago

Log in to reply

If all the cards are black, you can place the divider at the far left, making the "left pile" consist of 0 cards. Then the left pile has 0 black cards and the right pile has 0 red cards, satisfying the problem's requirement.

Stephen Brown - 3 years, 7 months ago

What if all the cards are red?

Louis Parker - 3 years, 7 months ago

Log in to reply

Yeah, I too thought of these cases.

Anubhav Saxena - 3 years, 7 months ago

in this case, place the line all the way on the right, so there are zero red cards on the right and zero black cards on the left.

Dom _ - 3 years, 7 months ago

1) Put the division-line on the left side of the arrangement of cards.

2) Count the number of red cards on the arrangement, and call this number N.

3) Move the division-line N places to the right.

In this way the number of black cards in the left side of the division-line is always equal to the number of red cards in the right side. To proof this, count the number of black cards in the left side of the division-line and call this number K. Notice that the number of red cards in the left side is N - K. Next, notice that the number of red cards in the right side is just the total number of red cards minus the number of red cards in the left side, and this is N - (N - K) = K. So we have K black cards in the left side and K red cards in the right side.

Notice that this works even with no cards on the table or with cards only of one color. You can check on the example above that the division-line is exactly after the fourth card and that the total number of red cards is exactly four. Furthermore, this kind of division is unique. This is because moving the line towards one side will increase the K number of one color or decrese it on the other side, always breaking the balance. To get a better intuition put one by one cards on a table and for every red card that appears move the division-line one space to the right, and if a black card appears leave the line in the same place.

If all the cards are red, any split into two groups will have no black cards on the left and some red cards on the right. I think this problem is flawed and needs to be clarified that there is always at least one black card and at least one red card in the set.

Thomas Raffill - 3 years, 7 months ago

Log in to reply

If all the cards are red, put them all on the black side. Now there are zero of the relevant color on each side.

Paul Phillips - 3 years, 7 months ago

Log in to reply

Then I do not see two groups. There could be one group (all the cards), or three groups (zero cards on the left, the red cards in the middle, and zero cards on the right).

Thomas Raffill - 3 years, 7 months ago

Log in to reply

@Thomas Raffill Ahh looks like they rephrased it to fix that.

Thomas Raffill - 3 years, 7 months ago

The example that Paul Phillips wrote is mentioned in general above in the problem statement: "You may divide the cards into two parts by picking a line before or after the whole cards (so that a part can contain 0 cards)". You can put the line before or after the whole set of cards, so even if there are no cards of one of the color, even if there are not cards at all there is still possible to this division.

Carlos Andrés Betancourt Baca - 3 years, 7 months ago

The question specified that a group nay contain 0 cards, how then is it still possible?

Lys Clarke - 3 years, 7 months ago

Log in to reply

For example: if you have only black cards on the table, then you put the blue line on the left of the all of them. In this way on the left side of the blue line there is nothing so the number of BLACK cards on this side is exactly zero. On the other side of the blue line there are also exactly zero RED cards because the arrangement of cards only contain black cards.

Carlos Andrés Betancourt Baca - 3 years, 7 months ago

Sort the cards : every red on the right and every black on the left. Draw a line between blanc and red cards. Without losing generality, assume there is more red than black. Take red cards to the black side until you satisfy the problem's condition. To get to any random line of cards, it is sufficient to perform permutations of cards, and permutations won't break the problem's conditions.

Tom Verhoeff
Apr 6, 2019

Here is a symmetric solution, using an invariant.

It involves two dividers \ell and r r with invariants:

  • r \ell \le r
  • the number of red cards to the left of \ell equals the number of black cards to the right of r r .

Initialization puts \ell to the far left, and r r to the far right, in which case both counts equal zero.

We are done when = r \ell = r .

When < r \ell < r , consider the color of the card immediately to the right of \ell , say a a , and the color of the card immediately to the left of r r , say b b . These cards are between \ell and r r . (N.B. It could be a single card, in which case a = b a = b ).

  • if a b a \ne b , then there are at least two cards between \ell and r r , and the invariant is preserved by moving \ell one card to the right, and r r one card to the left. Either both counts stay the same, or both counts increase by one.
  • if a = b = r e d a = b = \mathit{red} , then the invariant is preserved by moving r r one card to the left (both counts stay the same).
  • if a = b = b l a c k a = b = \mathit{black} , then the invariant is preserved by moving \ell one card to the right (both counts stay the same).

So, in all cases, the dividers are moved closer together while preserving the invariant.

Josiah Gillispie
Oct 24, 2017

Yes, and: The divider will always be as many red cards as you have from the left edge, counting the left edge itself as having 0 red cards in the distribution, regardless of how the cards are laid out.

Consider a random selection of cards and arrange them such that all red cards are to the left of all black cards.

Place the divider between the red and black cards. There are now 0 black cards to the left of the divider and 0 red cards to the right of the divider.

Any swap of two cards will have one of the following effects:

  • Two cards on the same side of the divider are swapped, meaning the counts we care about on either side do not change.
  • The two cards being swapped across the divider have the same color, meaning the counts we care about on either side do not change.
  • We swap a red card from the left to the right with a black card from the right to the left, meaning we increase both counts by 1.
  • We swap a red card from the right to the left with a black card from the left to the right, meaning we decrease both counts by 1.

...in all instances, both counts remain the same.

Any arrangement of the cards we have can be reached by making a finite number of 2-card swaps. (See Bubble Sort or any sorting algorithm from computer science.)

Thus, if we pick a random arrangement and keep our divider in the prescribed position (as many cards to the left of the divider as there are red cards in the selection), we will have as many black cards to the left of the divider as we have red cards to the right.

Vitrioil V
Oct 22, 2017

Let the number of cards be equal to n . Now,let's say n is the number of bits in a binary number. Let black card be denoted by 1 and red card be demoted by 0 . We have to prove solution exist for one and two bits of binary number i.e. solution exist for 0,1,00,01,10,11. 0=>|0 1=>1| 00=>|00 01=>0|1 10=>1|0 11=>11|

Since the solution exists for two bit numbers which are created by concatenating one bit number in any manner we can prove the solution exists when we concatenate the above numbers in any manner and any number of times,to get any possible number in binary. We considered one bit number to create numbers with odd number of bits.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...