Cards in the Dark | Adobe interview

You are standing in a pitch-dark room. A friend walks up and hands you a normal deck of 52 cards. He tells you that 13 of the 52 cards are face-up, the rest are face-down. These face-up cards are distributed randomly throughout the deck.
Your task is to split up the deck into two piles, using all the cards, such that each pile has the same number of face-up cards. The room is pitch-dark, so you can’t see the deck as you do this.
How can you accomplish this seemingly impossible task?

 

 

 

 

Solution :

Take the first 13 cards off the top of the deck and flip them over. This is the first
pile.The second pile is just the remaining 39 cards as they started. This works because 
if there are N face-up cards in within the first 13 cards, then there will be (13 - N)
face up cards in the remaining 39 cards. When you flip those first 13 cards, N of which
are face-up, there will now be N cards face-down, and therefore (13 - N) cards face-up,
which, as stated, is the same number of face-up cards in the second pile.

Leave a Reply

Your email address will not be published. Required fields are marked *

For Inserting code :
Paste your code in the comment form, select it and then click the language link

C | C++ | Java |

*