Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Alice and Bob
Alice and Bob are magicians. Alice asks a volunteer to randomly draw five playing cards from a deck. She takes the cards from the volunteer and looks at them without revealing them to anyone else. Alice then begins showing them to Bob one at a time. After the fourth card, Bob correctly guesses what the fifth card is. The secret to this trick was to come up with an algorithm that when given any five cards, could order four of them so that the fifth could be guessed by this order. (See where this is going yet?)

The challenge is for you to come up with said algorithm and implement it in QB or FB. Your program should describe the algorithm to the user, give him five random cards, ask for four cards back and then return the fifth. In other words, the user will be Alice and the program will be the audience member and Bob. (You just have to make sure that Bob is a separate function or that would be cheating.) There are many possible solutions, most of which are surprisingly simple.


1) Don't post your code here! Put it in a folder along with a compiled (.exe) version of your file and fileanchor it. You can post a link to it here. This will prevent people that want to solve this themselves from having to see the answer.

2) There will be no time limit on this challenge.

3) The winner will be the first person to come up with a working program that correctly guesses the fifth card every time. However, even if there is already a winner I encourage you to still participate. I would love to see different solutions to this.

4) If you haven't found a solution, don't peek at the others. This is really for your benefit. It's much more satisfying to find a solution yourself than to just read it.

5) If after a week no one has solved this, you can PM me for a hint. After another week, you can PM again for another hint. But like I said, it's much more rewarding to solve this on your own.

6) There won't be a prize for this because, well, I don't have anything :lol: I guess a hearty pat on the back from me will have to do. And of course all the fame and recognition you get from winning a Qbasicnews challenge!

7) Finally, this isn't my homework assignment so don't harass me with accusations. I have a solution of my own already.

If you have a question about this challenge or need something explained better just post it here. I tried to explain it as plainly as possible but I know it can still sound confusing. Hopefully someone will be able to put it in simpler terms.

Ok. Have fun!
hat were we arguing about again?
Well if the deck isn't shuffled isn't this kinda... too easy?
Not exactly. Since the audience member can choose any five cards from the deck it doesn't matter if it's shuffled or not. That was my fault though. I should have described it a little better. I just fixed my post to correct this.
hat were we arguing about again?
Can you really develop that sorta algorithim? Doesn't seem possible to me as it is completely random.... :???:

I am bad with probability and all that stuff though.
[Image: freebasic.png]
You mean like this?
(there are only 3 important parts, they're wrapped in dashed lines ------)

I don't see how else it's possible...
Happy new year, and you've left out a part of the puzzle. I've googled it and found solutions, but the critical aspect is that you're supposed to let Alice choose what cards she will pick and in what order. It's cheating to give us an algorithm in a paragraph and not give us an exact definition! Cry
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit to see rubbish in all its finest.
Damn, I forgot to say that Alice looks at the cards first. Agamemnus is right. Alice has to decide which four cards to give to Bob and in what order they go. You're supposed to figure that out by the way the trick plays out but I told it wrong so it's even more confusing. Tongue I knew this was gonna tough to explain. Please bear with me. This is a really cool challenge once you understand it. I'll edit my original post so it should be correct.

Sorry Sterling. It has to work for any five cards not just consecutive cards. And yes, it is possible. Oh, and happy new year!
hat were we arguing about again?
And also... one other thing...

They come up with a strategy beforehand.... of what Bob should reply given a set of 4 cards. Now it's really simple.

Here's the puzzle again in those terms:

Entity C randomly picks 5 cards from a deck of cards. Each card in the deck is unique. Entity C gives these cards to Entity A. Entity A shows 4 of these cards in any order to Entity B. The order of the cards and the identity of each card is the only information Entity B receives after the cards are shown.

Entity A and Entity B can share any information before Entity C picks these cards.

Create an algorithm such that, given these 4 cards, entity B can identify the fifth card.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit to see rubbish in all its finest.
Quote:Entity C randomly picks 5 cards from a deck of cards.
Any 5 cards, or any 5 contiguous cards?
Any 5 cards.
hat were we arguing about again?

Forum Jump:

Users browsing this thread: 1 Guest(s)