All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 Magic trick (Posted on 2007-05-11)
Two magicians A and B perform the following trick:

A leaves the room and B chooses 4 members from the audience at random. Each member chooses a card numbered from 1 to 100 (each chooses a different card) and after B has seen their cards he chooses a card from the remaining deck of cards. The 5 chosen cards are shuffled by an audience member and handed to A who just returned to the room. Prove that A is able to figure out which cards each member picked. Consider that the chosen members form a row and e.g. the leftmost member picks the first card and the rightmost member (B) picks the last card.

 No Solution Yet Submitted by atheron Rating: 4.1667 (6 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)

I ran the following program to try random selections of 4 cards, and in each case print on the first line the four numbers, in order, and the computed Z value. On the second line for each are the ak and Z values followed by the ak and Z values that the decoder, A, would deduce. In those instances where these differ from what B intended, the second line is also marked with an X.

Program:

match\$ = "1234,1243,1324,1342,1423,1432,2134,2143,2314,2341,2413,2431,"
match\$ = match\$ + "3124,3142,3214,3241,3412,3421,4123,4132,4213,4231,4312,4321"

CLS
DO
REDIM taken(100)
FOR i = 1 TO 4
DO
n = INT(RND(1) * 100 + 1)
IF taken(n) = 0 THEN cd(i) = n: orig(i) = n: taken(n) = 1: EXIT DO
LOOP
NEXT

j = 0
FOR i = 1 TO 100
IF taken(i) THEN
j = j + 1
cd(j) = i
END IF
NEXT

seq\$ = ""
FOR i = 1 TO 4
FOR j = 1 TO 4
IF orig(i) = cd(j) THEN seq\$ = seq\$ + LTRIM\$(STR\$(j))
NEXT
NEXT

Z = (INSTR(match\$, seq\$) + 4) / 5
FOR i = 1 TO 4
PRINT orig(i);
NEXT
PRINT Z

cd(5) = cd(1) + 100
FOR i = 1 TO 4
IF cd(i + 1) - cd(i) > 24 THEN ak = cd(i): EXIT FOR
NEXT
newNumb = ak + Z

s = 1
FOR r = 1 TO 5
IF newNumb < cd(s) THEN
recd(r) = newNumb
newNumb = 99999
ELSE
recd(r) = cd(s)
s = s + 1
END IF
NEXT

recd(6) = recd(1) + 100: recd(7) = recd(2) + 100
FOR i = 2 TO 6
diff = recd(i + 1) - recd(i - 1)
IF diff >= 25 THEN ak2 = recd(i - 1): Z2 = recd(i) - ak2: EXIT FOR
NEXT
PRINT ak; Z, ak2; Z2;
IF ak = ak2 AND Z = Z2 THEN PRINT :  ELSE PRINT " X"
REM
LOOP

Results:

`71  54  58  29  2229  22        29  2231  78  2  77  112  11         2  1182  71  5  42  235  23         5  2387  80  38  97  1538  15        38  1588  6  95  37  146  14         6  1453  77  6  60  116  11         6  1147  30  63  65  765  7         30  17  X27  28  83  59  228  2         28  299  92  23  70  2323  23        23  2399  25  54  11  2225  22        11  14  X100  68  2  58  232  23         2  2311  80  29  5  1229  12        11  18  X30  39  31  95  339  3         39  398  41  28  17  2441  24        28  13  X17  65  42  72  317  3         17  333  64  21  19  1833  18        21  12  X59  9  46  91  139  13         9  1327  79  38  29  638  6         38  692  64  63  43  2464  24        63  1  X10  57  70  92  110  1         10  184  3  55  92  133  13         3  1344  68  51  52  568  5         68  547  36  41  27  2247  22        41  6  X`

To take one of the X'ed examples, if the audience choices were

`C  D  E  F 47 30 63 65`

Rearranged this is

`30 47 63 65D  C  E  F    for Z=7`
`30  47  63  65 130 shows ak=65                     z+ak = 72`

A then sees 30  47  63  65  72
and appends 130 and 147:

30  47  63  65  72  130  147

The difference 63-30 shows up immediately as >= 25, so A perceives ak = 30 and Z=17  for ak+Z=47, and so reconstructs

`30 47 63 65 72E  B  F  C  D`

Is this mistaken decoding? No.  Let's start out with

`C  D  E  F65 72 30 63`
`30 63 65 72E  F  C  D       Z=17`
`30 63 65 72 130  ak=30; Z+ak = 47`

Present to A: 30 47 63 65 72; just as in the first problem where the audience chosen numbers were different. Both 47 30 63 65 and 65 72 30 63 resulted in the same coded value, 30 47 63 65 72. It was inevitable that different audience-chosen sets of 4 cards, in order, must share encoded sets of cards as there are only 75,287,520 of the latter and 94,109,400 of the former.

Out of the 23 computer-generated random sets of 4 cards, in 7 cases, the result of the decoding disagreed with the set being encoded.

Did Finland really use just 100 cards in the statement of the problem?

 Posted by Charlie on 2007-05-13 03:09:48

 Search: Search body:
Forums (0)