Sunday, October 1, 2023

HP 15C and TI-60: The Lottery Probability Function

HP 15C and TI-60:  The Lottery Probability Function



The Lottery Probability Function


The expression, of what I call the Lottery Probability Function:


prob =  nCr(k, b) × nCr(n-k, k-b) ÷ nCr(n, k)


where:


*  nCr is the combination function.  nCr(x,y) = x! ÷ (y! × (y - x)!)

*  n = the number of total balls in the lottery

*  k = the number of balls drawn

*  b = the number of balls your ticket matches

*  prob = probability 


Lottery odds are often stated as "1 in number" instead of decimal form.  The number is the statement "1 in number" is 1/p.   For example, "1 in 5" means that the probability is 1/5 or 0.20.  (20%)



HP 15C (Emulator) Program Code


Program Size:

19 steps, 30 bytes


Store before running label A:

R1 = n

R2 = k

R3 = b



Step : Step Code : Key

001 : 42,21,11 : LBL A

002 : 45, 2 : RCL 2

003 : 45, 3 : RCL 3

004 : 43,40 : Cy,x

005 : 44, 0 : STO 0

006 : 45, 1 : RCL 1

007 : 45,30, 2 : RCL- 2

008 : 45, 2 : RCL 2

009 : 45,30, 3 : RCL- 3

010 : 43,40 : Cy,x

011 : 44,20, 0 : STO× 0

012 : 45, 1 : RCL 1

013 : 45, 2 : RCL 2

014 : 43,40 : Cy,x

015 : 44,10, 0 : STO÷ 0

016 : 45, 0 : RCL 0

017 : 15 : 1/x

018 : 44, 0 : STO 0

019 : 43, 32 : RTN


Caution:  HP 15C Limited Edition.  It is a known bug when the combination (Cy,x) and permutation (Py,x) are run multiple times, the display flashes as if a overflow error occurs.  The program otherwise runs fine (with the examples I tested - 2011/04/15 firmware).   

To eliminate unnecessary flashing, use the following key sequence:

[ GTO ] ( A ) [ R/S ]


Full a list of known bugs, as compiled by Katie Wasserman, click here:

https://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/articles.cgi?read=1089



TI-60 (Programmable Scientific/Advanced Scientific) Program Code


57 steps.   No commands are merged.  


For the combination (and permutation) functions, the number must be formatted as the following: nnn.rrr


The command sequence INV EE cancels scientific notation display.  


Step : Step Code : Key

01 : 71 : RCL

02 : 02 :  2

03 : 85 : +

04 : 03 : 3

05 : 55 : ÷

06 : 01 : 1

07 : 42 : EE

08 : 03 : 3

09 : 95 : =

10 : 80 : nCr

11 : 61 : STO 

12 : 00 : 0

13 : 71 : RCL

14 : 01 : 1

15 : 85 : +

16 : 71 : RCL

17 : 02 : 2

18 : 55 : ÷

19 : 01 : 1

20 : 42 : EE

21 : 03 : 3

22 : 95 : =

23 : 80 : nCr

24 : 61 : STO

25 : 55 : ÷

26 : 00 : 0

27 : 71 : RCL

28 : 01 : 1

29 : 75 : -

30 : 71 : RCL

31 : 01 : 1

32 : 85 : +

33 : 53 : (

34 : 71 : RCL

35 : 02 : 2

36 : 75 : -

37 : 71 : RCL

38 : 03 : 3

39 : 54 : )

40 : 55 : ÷

41 : 01 : 1

42 : 42 : EE

43 : 03 : 3

44 : 95 : =

45 : 80 : nCr

46 : 61 : STO

47 : 65 : ×

48 : 00 : 0

49 : 71 : RCL

50 : 00 : 0

51 : 76 : 1/x

52 : 61 : STO

53 : 00 : 0

54 : 12 : INV

55 : 42 : EE

56 : 13 : R/S

57 : 22 : RST



Examples


1.  49 balls and 6 are drawn.    Set up variables:  R1 = n =  49 and R2 = k = 6.


R3 = b = 6:  1 in 13,983,816

R3 = b = 5:  1 in 54,200.83721

R3 = b = 4:  1 in 1,032.3396899


2.  52 balls and 6 are drawn.  Set up variables:  R1 = n = 52 and R2 = k = 6.


R3 = b = 6:  1 in 20,358,520

R3 = b = 5:  1 in 73,762.75362

R3 = b = 4:  1 in 1,311.337842


Note that this function does not take the power ball, which only 1 is drawn in addition to the lottery balls, into account.   If you have a power ball of p balls, we can calculate the odds as follows:


You match the power ball:

prob = 1 ÷ p × nCr(k, b) × nCr(n-k, k-b) ÷ nCr(n, k)


1 in odds:  1/prob


You don't match the powerball:

prob = (p - 1) ÷ p × nCr(k, b) × nCr(n-k, k-b) ÷ nCr(n, k)


1 in odds:  1/prob



Source:

"Lottery mathematics".  Wikipedia.  Last edited July 10, 2023.  Retrieved July 23, 2023.  https://en.wikipedia.org/wiki/Lottery_mathematics


Eddie 


All original content copyright, © 2011-2023.  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. 


TI 84 Plus CE: Consolidated Debts

TI 84 Plus CE: Consolidated Debts   Disclaimer: This blog is for informational and academic purposes only. Financial decisions are your ...