Showing posts with label playing cards. Show all posts
Showing posts with label playing cards. Show all posts

Saturday, October 8, 2022

Drawing Random Numbers with Playing Cards 


An Easy Way to Get Random Numbers

Need an easy and fun way to draw random is to use a playing deck of cards.  No electricity or potentially expensive electronic devices are needed, and your shuffling skills will improve dramatically.  





Take a regular deck of cards, and you will only need 40 cards.  Get all the Aces, ones through nines, and one set of face cards.   Assign the following cards as the following values:


Aces:  1

Twos:  2

Threes: 3

Fours: 4

Fives: 5

Sixes: 6

Sevens: 7

Eights: 8

Nines: 9

Any set of face card or tens: 0  (I use Jacks, see the pictures above.  You can use Queens, Kings, or Tens)


To get a random number:

1.  Shuffle the deck

2.  Draw up to four cards 

3.  That card becomes the random number.  Insert a decimal point anywhere if appropriate.  


Why only up to four cards?  There are only four digits available per deck.  We are generating a samples with no replacement.  


Sample four digit numbers:

8-clubs, Ace-hearts, 2-clubs, 5-diamonds:  8125

2-diamonds, Ace-clubs, 3-clubs, 5-spades:  2135

4-hearts, 8-spades, 3-diamonds, 9-spades: 4839

4-hearts, 3-diamonds, 9-slides, 8-clubs: 4398

Jacks-clubs, Ace-clubs, 2-diamonds, 2-spades: 0122


How many possible permutations are possible with this deck?

2 digits:  nPr(40, 2) = 1560

3 digits:  nPr(40, 3) = 59,280

4 digits:  nPr(40, 4) = 2,193,360



Can we create a program to generate random numbers using this method?  

Yes.   I am using the TI-84 Plus CE to for this program.   The TI-84 has a randIntNoRep function, which generates a list of random integers without replacement.   The nice part of the is we are working with base 10, so the use of a remainder function will give the results we want: 0 through 9.  


Syntax:


Random Sample of Integers Without Replacement:

randIntNoRep(low, high, size of the sample)


Remainder function, which can be used as the modulus function.

remainder(x, y):  returns the remainder of x ÷ y


The program RANDDECK will generate a list and draw a histogram.


TI-84 Plus CE Program:  RANDDECK





"2022-08-16 EWS"

ClrHome

Disp "MAKE A 4 DIGIT,","NUMBER FROM A DECK 0-9"

Input "NO OF TRIALS: ", N

For(I,1,N)

randIntNoRep(1,40,4)→L6

remainder(L6,10)→L6

sum(L6*{1000,100,10,1})→N

If I=1

Then

{N}→L5

Else

augment(L5,{N})→L5

End

End

Pause L5

ClrHome

Disp "PRESS [ENTER] TO"

Pause "DISPLAY HISTOGRAM"

Plot1(Histogram,L5,1,BLUE)

PlotsOn 1

ZoomStat


Here is an example.



Until next time,


Eddie


All original content copyright, © 2011-2022.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Sunday, January 3, 2016

TI-84 Plus and HP Prime: Card Sharks Odds Program

TI-84 Plus and HP Prime:  Card Sharks Odds Program

HAPPY NEW YEAR! 

Cards and Calculations.   By the way, is the next card higher or lower than the 9?


The game show Card Sharks may have long been off-air except for reruns on GSN or BUZZR (or even finding videos on YouTube), the game show is still popular.  It is a simple game involving a standard deck of 52 cards.  The object is to predict whether the next card is higher in rank or lower in rank than the preceding card.  In Card Sharks, aces always count as high.  Along with aces, twos are very desirable, while eights are the worst cards in the deck.

Quick Synopsis*:  Each player works on his/her own deck of cards.  The first two games have 5-card hands while the third, if needed has only 3.  A player got control if they won (usually) a survey-type toss up question.  A game is won when a hand is completed or wins the sudden-death question. Winning 2 games won the match for the champion.  The champion got to play Money Cards, where a seven card hand was dealt in two rows of 3 and one final card.  The player then placed bets on whether the card was higher or lower, at even odds.  The last bet had to at least half of the player’s bankroll.

* This was the general game play, for all of the details of the incarnations of game show, please click here:  http://gameshows.wikia.com/wiki/Card_Sharks  (Game Shows Wiki).

The program CSODDS tracks the odds of whether the next card is higher or lower.  CSODDS assumes a 52 card deck (no jokers).   All entries are numerical, hence:

Jacks = 11
Queens = 12
Kings = 13
Aces = 14

You are asked if you want to continue after each card.  The program accounts for the number of cards in each deck.  Have fun!

TI-84 Plus Program CSODDS




seq(4,X,1,14,1)→L₆
0→L₆(1)
While sum(L₆)>0
Disp "J=11 Q=12 K=13 A=14"
Input "CARD:",C
If L₆(C)≠0
Then
L₆(C)-1→L₆(C)
0→L
For(K,2,C-1)
L+L₆(K)→L
End
0→H
For(K,C+1,14)
H+L₆(K)→H
End
Disp "ODDS NEXT CARD IS"
Disp "HIGHER:",H/sum(L₆)
Disp "LOWER:",L/sum(L₆)
Disp "CARDS USED:",52-sum(L₆)
Pause
Else
Disp "NOT AVAILABLE"
End

Menu("CONTINUE?","YES",1,"NO",2)
Lbl 1
End
Lbl 2

HP Prime Program CSODDS



EXPORT CSODDS()
BEGIN
// Card Sharks Odds
// Jan 3 2016 EWS
// Standard deck of 52 cards

LOCAL L6,C,L,H,K,R;
L6:=MAKELIST(4,X,1,14,1);
L6(1):=0;


WHILE ΣLIST(L6)>0 DO
INPUT(C,"Next Card","Card:",
"J=11 Q=12 K=13 A=14");

IF L6(C)≠0 THEN
L6(C):=L6(C)-1;
//L:=ΣLIST(SUB(L6,1,C-1))/
//ΣLIST(L6);
//H:=ΣLIST(SUB(L6,C+1,14))/
//ΣLIST(L6);

L:=0;
FOR K FROM 2 TO C-1 DO
L:=L+L6(K);
END;

H:=0;
FOR K FROM C+1 TO 14 DO
H:=H+L6(K);
END;
L:=L/ΣLIST(L6);
H:=H/ΣLIST(L6);
R:=52-ΣLIST(L6);
PRINT();
PRINT("CARD: "+C);
PRINT("ODDS NEXT CARD IS");
PRINT("HIGHER: "+H);
PRINT("LOWER: "+L);
PRINT("CARDS USED: "+R);
WAIT(0);

ELSE
MSGBOX("CARD N/A");
END;

// Continue?
K:=1;
CHOOSE(K,"Continue?",
{"Yes","No"});
IF K==2 THEN
RETURN;
END;

END;

END;


Sample 10-Card Hand (results rounded to 3 decimal places):

Card
Odds next Card is Higher
Odds Next Card is Lower
Card 1:  K (13)
0.078
0.863
Card 2:  3
0.860
0.080
Card 3:  J (11)
0.224
0.714
Card 4:  9
0.375
0.563
Card 5:  7
0.532
0.404
Card 6:  A (14)
0.000
0.935
Card 7:  6
0.600
0.333
Card 8:  K (13)
0.068
0.886
Card 9:  8
0.442
0.488
Card 10: 4
0.762
0.167

In the near future, I am going to present some programs for the HP 15C.  I tend to emphasize graphing calculators due to (a) availability and (b) programs can be more complex due to the increased memory.  

Eddie



This blog is property of Edward Shore.  2016

Sunday, January 5, 2014

Playing Cards: Odds That The Next Card is Higher or Lower

In the classic game "Card Sharks", contestants had to guess and wager whether the proceeding card is higher or lower. The card game is popular to watch on TV and to play on yourself. All it takes a deck of cards to play.

This blog entry deals with the odds of whether the next card is higher or lower. Several assumptions: the odds are calculated with a standard 52 card deck without Jokers. The tables deal with the first cards drawn from the top of the deck.

Table 1: One card is drawn from the top of the deck.

Table 2: One card is drawn. A second drawn which is lower than the first card. Examples: Ace then King, Ten then Six.

The second card is the current card.

Table 3: One card is drawn. A second drawn which is higher than the first card. Examples: King then Ace, Six then Ten.

The second card is the current card.

Table 4: A pair of cards are drawn. Example: A pair of Eights.

General strategies of Card Sharks consisting of:
* Betting a lot on lower when you have an Ace or King
* Betting a lot on higher when you have a 2 or 3
* Betting minimum on a 7, 8, or 9 (middle ranks)


Analyzing a Hand

In general, the odds of whether cards are higher or lower as the number of cards decrease. Let's see how the odds change during a 8 card hand.

** Odds are rounded to 3 digits in this analysis.

Here is an Example Hand:

1st Card: King
Odds the next card is higher: 0.078
Odds the next card is another King: 0.059
Odds the next card is lower: 0.863

2nd Card: 10
Odds the next card is higher: 0.300
Odds the next card is another 10: 0.060
Odds the next card is lower: 0.640

3rd Card: 2
Odds the next card is higher: 0.939
Odds the next card is another 2: 0.061
Odds the next card is lower: 0.000

4th Card: 6
Odds the next card is higher: 0.624
Odds the next card is another 6: 0.063
Odds the next card is lower: 0.313

5th Card: 4
Odds the next card is higher: 0.787
Odds the next card is another 4: 0.064
Odds the next card is lower: 0.149

6th Card: 4
Odds the next card is higher: 0.805
Odds the next card is another 4: 0.043
Odds the next card is lower: 0.152

7th Card: King
Odds the next card is higher: 0.089
Odds the next card is another King: 0.044
Odds the next card is lower: 0.867

8th Card: 5
(The game ends).


Shuffle up and deal!

Eddie


This blog is property of Edward Shore. 2014

Python – Earth’s Radius and Gravity in US Units

Python – Earth’s Radius and Gravity in US Units Introduction The following script, gravus2.py, estimates the Earth’s gravity i...