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