The Best Card Trick —
I gave a talk on The Best Card Trick at the Boston Haskell meetup tonight, and then we implemented the technique together in Haskell as a group. Afterwards, we compared our program with this one that my friend Mark Carroll wrote a long time ago. Here’s a summary of the trick from the paper’s abstract:
You, my friend, are about to witness the best card trick there is. Here, take this ordinary deck of cards, and draw a hand of five cards from it. Choose them deliberately or randomly, whichever you prefer — but do not show them to me! Show them instead to my lovely assistant, who will now give me four of them, one at a time: the 7♠, then the Q♥, the 8♣, the 3♦. There is one card left in your hand, known only to you and my assistant. And the hidden card, my friend, is the K♠.
In even-more-mind-blowing news, today John McCain gave a talk about OLPC.
oh wow, thank you for the link =)
not being a science-y type it took me five minutes to get my head around the concept, but the bonus is not being a science-y type means my friends won’t all know about it already. I have to practice now 🙂
How about a little program?
using System;
namespace GuessTheNumber
{
class Program
{
private static int[] indexer = new int[21] {
0, 3, 6, 9, 12, 15, 18,
1, 4, 7, 10, 13, 16, 19,
2, 5, 8, 11, 14, 17, 20 };
static void Main(string[] args)
{
Start:
try
{
while (true)
{
Console.WriteLine(“nMemorize a digit and enter the row number in which it is located…n”);
int[] digits1 = new int[21] { 48, 22, 36, 37, 41, 45, 55, 59, 60, 66, 63, 72, 77, 84, 80, 99, 94, 90, 91, 93, 92 };
int[] digits2 = new int[21];
for (int i = 0; i < 3; i++) { Deal(digits1); Console.Write("nEnter row number: "); int key = GetInput(Console.ReadLine()); switch (key) { case 1: IndexToIndex(digits1, digits2, 0, 7, 7); IndexToIndex(digits1, digits2, 7, 0, 7); IndexToIndex(digits1, digits2, 14, 14, 7); break; case 2: IndexToIndex(digits1, digits2, 7, 7, 7); IndexToIndex(digits1, digits2, 0, 14, 7); IndexToIndex(digits1, digits2, 14, 0, 7); break; case 3: IndexToIndex(digits1, digits2, 14, 7, 7); IndexToIndex(digits1, digits2, 0, 14, 7); IndexToIndex(digits1, digits2, 7, 0, 7); break; } digits1 = digits2; digits2 = new int[21]; } Console.WriteLine("nYour number is: {0}n", digits1[digits1.Length / 2]); Console.Write("nPress Enter to continue..."); Console.ReadLine(); Console.Clear(); } } catch (Exception ex) { Console.Write("n{0} Press Enter to play again...", ex.Message); Console.ReadLine(); Console.Clear(); goto Start; } } private static void Deal(int[] digits) { Console.WriteLine(); int count = 0; for (int i = 0; i < digits.Length; i += 7) { Console.Write("(ROW-{0}) t", (count++)+1); for (int j = i; j < (i + 7); j++) { Console.Write(digits[indexer[j]] + "t"); } Console.Write("n"); } } private static void IndexToIndex(int[] sourceArray, int[] targetArray, int sourceIndex, int targetIndex, int count) { while (count > 0)
{
targetArray[targetIndex++] = sourceArray[indexer[sourceIndex++]];
count–;
}
}
private static int GetInput(string value)
{
int input;
if (int.TryParse(value, out input))
{
if (input < 1 || input > 3)
{
throw new Exception(“Input must be between 1 and 3.”);
}
}
else
{
throw new Exception(“Input must be an integer.”);
}
return input;
}
}
}
Any chance you have that pdf on a non-password-protected site?
I’m kind of a card and math guy, so I’m interrested as to how this works.
> Any chance you have that pdf on a non password-protected site?
I don’t, but Googling [“The Best Card Trick” kleber] will bring up the same password-protected URL with a “Quick View” button that brings up the PDF. (There are some other direct hits to a copy of the PDF farther down the search results, too.)
Thanks for the link. Nice to know my senator is up to something I can support.
LOL! Card tricks are always welcome, even if you have to employ a trick to get to view the workings of the trick. Sounds tricky, hey!
Thank you for the explanation on getting beyond the password protection, Chris. There is nothing worse than getting the dreaded password prompt when you really want to access something.
It is great that prominent political figures are supporting the one laptop per child initiative. The more people throw their weight behind the initiative the better.
Catch you later!
Richie