flat assembler
Message board for the users of flat assembler.

 Index > Heap > Card Trick
Author
Walter

Joined: 26 Jan 2013
Posts: 143
Walter

While not mathemaically mind-blowing,
this is a fairly good trick.

Kids would love it.

See how good it is for you.

http://cardtrick.me/
27 Nov 2013, 02:18
matefkr

Joined: 02 Sep 2007
Posts: 1291
Location: Ukraine, Beregovo
matefkr
i dont think my kids would love it.
27 Nov 2013, 10:48
sleepsleep

Joined: 05 Oct 2006
Posts: 8904
Location: ˛　　　　　　　　　　　　　　　　　　　　　　　　　　　　　⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
so 3 chances to get 1 out of 7.

card is missing sometime, idk if you notice,
then sometime it guess on where you click.

but anyone want to detail the math?
27 Nov 2013, 12:43
typedef

Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
That eye
28 Nov 2013, 02:24
typedef

Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Code:
```// define CARDS[0..2][0..6]; // 3 by 7 table

static const CARD_LOOKUP_TABLE [0..51] = [
// all possible cards
]

// first time grab 21 random cards from the card stack. We will work with this.

CARDS[
[c00,c01,c02,c03,c04,c05,c06],
[c10,c11,c12,c13,c14,c15,c16],
[c20,c21,c22,c23,c24,c25,c26]
];

while (user_is_playing)
{
shuffle_cards:
for(row = 0; row < CARDS.rows; row++){
for(col = 0; col < CARDS.cols; col++){
CARDS[row][col] = next_random_from_selected();
}
}

for(int tries = 0; tries < 3; tries++)
{
sel_row = gui_display_cards_and_get_user_selected_row();

for(col = 0; col < CARDS.cols; col++)
{
CARDS[sel_row][col]++; // increment number of appearences to each card in this row
}
shuffle_cards();
}

index = -1;

// determine card by 3 times of appearances.
for(col = 0; col < CARDS.cols; col++)
{
if(CARDS[sel_row][col] == 3){
index = col;
}
}

// determine card by unknown highest number of appearances.
max = CARDS[sel_row][0];
if(index == -1){
for(col = 0; col < CARDS.cols; col++)
{
max = CARDS[sel_row][col] > max ? CARDS[sel_row][col] : max;
}

// simple linear search for column containing highest value we found
for(col = 0; col < CARDS.cols; col++)
{
if(CARDS[sel_row][col] == max)
{
index = col;
break;
}
}
}

gui_show_user_card_and_illuminati_eye(CARDS[sel_row][index]);

if(user.browser.tab(3).close()){
user_is_playing = false;
user_is_watching_porn = true;
}
}

while(user_is_watching_porn){
user.make_sound("oooo yeaaaah");
// fap fap fap fap fap
}
```
28 Nov 2013, 02:57
Walter

Joined: 26 Jan 2013
Posts: 143
Walter
If one was wanting to implement typedef's algorithm, I suppose card images would be required.

I like these:

28 Nov 2013, 04:02
typedef

Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
I thought of two approaches.

One strict (above) and one bruteforce.

Strict version forces player to select rows only 3 times which guarantees success provided the game uses a good PRNG. Determining the card is just checking the last selected row for the cell with the highest value.(See NOTE 2 below)

The bruteforce version would not be restricted to any number of tries (where tries > 0). To determine the card, the game would use elimination/divide and conquer method. Which is faster in my opinion.
After the first try(tries >= 2), the cell with the highest number in the selected row is the card. (see NOTE 1)

NOTE 1:
In case of a collision, the x number of cells would be "followed", diving and conquering each selected row, until the last selected row contains only one of the cards.
Yes it sounds like cheating but it's the only way to solve it

NOTE 2:
In case of a collision (two cards end up on the same rows 3 times) (bad PRNG), the game would have to pick one card randomly since it can't go for 4th try.

Factors to a good engine:

Good PRNG and more cards = less chances of collision.
28 Nov 2013, 04:35
tthsqe

Joined: 20 May 2009
Posts: 729
tthsqe
This is a good trick, and here are the details on how the applet is working. Unfortunately, the applet does not detect when the user is lying! For example, anyone who select the first row all three times is clearly lying if the applet follows the algorithm below.
The process is easy enough that the dealer can still do it while severely drunk. (No complicated program required):
repeat 3 times
1) dish out the cards to the rows in the order 1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3
2) without changing the order of the cards in the rows, put the cards backinto a pile while inserting the row contains the user's card in the middle
end repeat
the user's card is the 11th in the pile

notice that three selection of one out of three contains enough entropy because 3^3 > 21. This is far from a proof though.

example:
Code:
```suppose user's card is 1
initial dish:
1  4  7 10 13 16 19    <= first row selected
2  5  8 11 14 17 20
3  6  9 12 15 18 21
stack up cards as:
2  5  8 11 14 17 20  1  4  7 10 13 16 19  3  6  9 12 15 18 21
dish:
2 11 20  7 16  6 15
5 14  1 10 19  9 18    <= second row selected
8 17  4 13  3 12 21
stack up cards as:
2 11 20  7 16  6 15  5 14  1 10 19  9 18  8 17  4 13  3 12 21
dish:
2  7 15  1  9 17  3    <= first row selected
11 16  5 10 18  4 12
20  6 14 19  8 13 21
stack up cards as:
11 16  5 10 18  4 12  2  7 15  1  9 17  3 20  6 14 19  8 13 21
^
user's card is the middle one    ```

Last edited by tthsqe on 28 Nov 2013, 08:07; edited 3 times in total
28 Nov 2013, 07:02
tthsqe

Joined: 20 May 2009
Posts: 729
tthsqe
This is exactly the shuffling algorithm used by the applet. If the look carefully, the will notice that your card is always getting closer to the center monotonically. Here is a proof that is always works:
Code:
```the process of 1) followed by 2) as described above introduces a function on the user's card position as follows:

i :  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21
p(i):  8  8  8  9  9  9 10 10 10 11 11 11 12 12 12 13 13 13 14 14 14

It is simple matter verify that p(p(p(i))) is always 11.

i :  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21
p(i):  8  8  8  9  9  9 10 10 10 11 11 11 12 12 12 13 13 13 14 14 14
p(p(i)): 10 10 10 10 10 10 11 11 11 11 11 11 11 11 11 12 12 12 12 12 12
p(p(p(i))): 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11     ```
28 Nov 2013, 07:32
typedef

Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Lol. I just looked at it and the game is a fraud. It doesn't do anything magical other than shift cells around

This isn't randomization. It's predefined so it's easy to win. What a cheat !!

They're using a prediction algorithm (no randomization) I guess. They simply shift the cells and determine which cell the card will end up in.

Good game though.

I hope you can see the colors.

 Description: Filesize: 681.87 KB Viewed: 2520 Time(s)

28 Nov 2013, 09:05
tthsqe

Joined: 20 May 2009
Posts: 729
tthsqe
typdef, I wouldn't exactly call it cheating. If your card was a 10 of spades, then it starts out in position 21 (row 3 col 7). p(21)=14, so it then goes to row 2 col 5. p(14)=12, so it then goes to row 3 col 4. Finally, p(12)=11, so it goes to the center. tada! As I said before, the more disappointing feature is that is does not check if you are lying. Try it for yourself. There should be 3^3-21 = 6 ways to lie.
28 Nov 2013, 09:21
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsCompiler InternalsIDE DevelopmentOS ConstructionNon-x86 architecturesHigh Level LanguagesProgramming Language DesignProjects and IdeasExamples and Tutorials Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou can attach files in this forumYou can download files in this forum