# Logic puzzle, generic form

This logic puzzle has stumped me for some time now:

You are in a dark room with a deck of cards in front of you. 30 cards are face down and the rest are face up. How can you separate the cards into two piles such that each pile has the same number of face-up cards? You are allowed to turn over any amount of cards, but it is too dark to see.

Can this be solved generically for any number of face-up and face-down cards?

-
Cute problem.${}$ – Rick Decker Jul 18 '13 at 19:17

We don't know how big to make the piles. The only number given in the problem is $30$, so let's try tha‌t: suppose we make a pile with $30$ cards (w‌ithout turning over any card yet). It will have some number of face-down cards, say $k$, and the rest of the cards ($30-k$ of them) will be face-up.

The other pile has the remaining cards. This includes the rest of the original face-down cards‌ (there were $30$ total, and some number $k$ are in the first-pile, so there are $30-k$ here), and some unknown number of face-up cards.

To summarize:‌ the first pile has $k$ face-down cards and $30-k$ face-up cards; the second pile has $30-k$ face-down cards and some number of face-up cards.

Now we want to make the number of face-up cards equal in the two piles. I‌t should be obvious how to achieve that from here. ‌:-)

So yes, the problem can be solved for any number of face-down cards in place of $30$, provided we are told what the number is.‌ We don't need to be told what the number of face-up cards is.

-
"I‌t should be obvious how to achieve that from here." Perhaps, but I had to stare at your solution for a while before I realized I should just flip one of the piles :) – Richard Venable Feb 17 '14 at 23:27
@RichardVenable: Yes, it's that long staring followed by the "aha" moment (or rather "oh of course, why didn't I think of this before!" moment) that makes these puzzles so much fun. :) I didn't want to spoil it too much by just stating it blandly. – ShreevatsaR Feb 18 '14 at 4:16

Hint: It can be solved for any number of face-up cards, as long as you know how many there are.

-