import math
from math import comb as MC
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.ticker import StrMethodFormatter as SMF
import pandas as pd
import seaborn as sns
suits = []
nothings = []
pairs = []
twopairs = []
threekinds = []
straights = []
flushes = []
fullhouses = []
fourkinds = []
straightflushes = []
royalflushes = []
fivekinds = []
for i in range(3, 31) :
suits.append(i)
d = MC(13*i, 5)
pair = 13 * MC(i, 2) * MC(12, 3) * i ** 3 / d
pairs.append(pair)
twopair = MC(13, 2) * MC(i, 2) * MC(i, 2) * 11 * i / d
twopairs.append(twopair)
threekind = 13 * MC(i, 3) * MC(12, 2) * i ** 2 / d
threekinds.append(threekind)
straight = (10 * i**5 - 10*i) / d
straights.append(straight)
flush = (i * MC(13, 5) - 10*i) / d
flushes.append(flush)
fullhouse = 13 * MC(i, 3) * 12 * MC(i, 2) / d
fullhouses.append(fullhouse)
fourkind = 13 * MC(i, 4) * 12 * i / d
fourkinds.append(fourkind)
straightflush = 9*i / d
straightflushes.append(straightflush)
royalflush = i / d
royalflushes.append(royalflush)
if i < 5 :
fivekind = 0
else :
fivekind = 13 * MC(i, 5) / d
fivekinds.append(fivekind)
nothing = 1 - (pair + twopair + threekind + straight + flush + fullhouse + fourkind + straightflush + royalflush + fivekind)
nothings.append(nothing)
print(i, straight, fullhouse)
3 0.0041684252210568 0.000812842918106076 4 0.003924646781789639 0.0014405762304921968 5 0.0037772909269471935 0.0018886454634735967 6 0.00368052999631947 0.00221684432210748 7 0.0036125568864817216 0.002465570075023775 8 0.003562320823744282 0.002659866215062397 9 0.0035237298766689173 0.002815546116089603 10 0.0034931763896239266 0.0029429460852277186 11 0.0034683960063883875 0.003049061243320939 12 0.003447898684091633 0.0031387767331041076 13 0.0034306649990944052 0.0032155997815041175 14 0.0034159744838844035 0.0032821099000489335 15 0.0034033037818858316 0.0033402447792900487 16 0.0033922636852760707 0.0033914872458882758 17 0.0033825588115379618 0.003436990792413285 18 0.003373960976704669 0.00347766588251496 19 0.00336629113689718 0.00351424056227849 20 0.0033594068494756215 0.003547303848181597 21 0.0033531933832349477 0.0035773373259645564 22 0.003347557297278997 0.0036047385257656044 23 0.003342421724858308 0.003629838460915699 24 0.0033377228568075104 0.0036529149590981995 25 0.003333407283323185 0.0036742029161229996 26 0.003329429959362441 0.0036939022690448222 27 0.0033257526294943576 0.003712184258410654 28 0.0033223425956096938 0.003729196392580513 29 0.003319171743509136 0.0037450664171061986 30 0.0033162157670933792 0.003759905514027895
data = list(zip(suits,
nothings,
pairs,
twopairs,
threekinds,
straights,
flushes,
fullhouses,
fourkinds,
straightflushes,
royalflushes,
fivekinds))
names = ["Suits",
"High Card",
"Pair",
"Two Pair",
"Three-of-a-Kind",
"Straight",
"Flush",
"Full House",
"Four-of-a-Kind",
"Straight Flush",
"Royal Flush",
"Five-of-a-Kind"]
df = pd.DataFrame(data = data,
columns = names)
df
Suits | High Card | Pair | Two Pair | Three-of-a-Kind | Straight | Flush | Full House | Four-of-a-Kind | Straight Flush | Royal Flush | Five-of-a-Kind | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 3 | 0.532308 | 0.402357 | 0.040236 | 0.013412 | 0.004168 | 6.653849e-03 | 0.000813 | 0.000000 | 4.689478e-05 | 5.210532e-06 | 0.000000 |
1 | 4 | 0.501177 | 0.422569 | 0.047539 | 0.021128 | 0.003925 | 1.965402e-03 | 0.001441 | 0.000240 | 1.385169e-05 | 1.539077e-06 | 0.000000 |
2 | 5 | 0.482360 | 0.432815 | 0.051938 | 0.025969 | 0.003777 | 7.730129e-04 | 0.001889 | 0.000472 | 5.448016e-06 | 6.053351e-07 | 0.000002 |
3 | 6 | 0.470004 | 0.438935 | 0.054867 | 0.029262 | 0.003681 | 3.629372e-04 | 0.002217 | 0.000665 | 2.557897e-06 | 2.842108e-07 | 0.000004 |
4 | 7 | 0.461324 | 0.442981 | 0.056955 | 0.031641 | 0.003613 | 1.922181e-04 | 0.002466 | 0.000822 | 1.354709e-06 | 1.505232e-07 | 0.000006 |
5 | 8 | 0.454908 | 0.445844 | 0.058517 | 0.033438 | 0.003562 | 1.110887e-04 | 0.002660 | 0.000950 | 7.829277e-07 | 8.699196e-08 | 0.000008 |
6 | 9 | 0.449980 | 0.447973 | 0.059730 | 0.034842 | 0.003524 | 6.859456e-05 | 0.002816 | 0.001056 | 4.834386e-07 | 5.371539e-08 | 0.000010 |
7 | 10 | 0.446079 | 0.449617 | 0.060698 | 0.035969 | 0.003493 | 4.461232e-05 | 0.002943 | 0.001144 | 3.144173e-07 | 3.493526e-08 | 0.000011 |
8 | 11 | 0.442914 | 0.450922 | 0.061489 | 0.036894 | 0.003468 | 3.025370e-05 | 0.003049 | 0.001220 | 2.132211e-07 | 2.369123e-08 | 0.000013 |
9 | 12 | 0.440297 | 0.451984 | 0.062148 | 0.037665 | 0.003448 | 2.123447e-05 | 0.003139 | 0.001284 | 1.496556e-07 | 1.662840e-08 | 0.000014 |
10 | 13 | 0.438096 | 0.452864 | 0.062704 | 0.038319 | 0.003431 | 1.533949e-05 | 0.003216 | 0.001340 | 1.081092e-07 | 1.201213e-08 | 0.000015 |
11 | 14 | 0.436220 | 0.453604 | 0.063181 | 0.038880 | 0.003416 | 1.135546e-05 | 0.003282 | 0.001389 | 8.003064e-08 | 8.892293e-09 | 0.000017 |
12 | 15 | 0.434602 | 0.454237 | 0.063593 | 0.039367 | 0.003403 | 8.584898e-06 | 0.003340 | 0.001432 | 6.050437e-08 | 6.722708e-09 | 0.000017 |
13 | 16 | 0.433192 | 0.454782 | 0.063954 | 0.039793 | 0.003392 | 6.610087e-06 | 0.003391 | 0.001470 | 4.658636e-08 | 5.176263e-09 | 0.000018 |
14 | 17 | 0.431953 | 0.455258 | 0.064272 | 0.040170 | 0.003383 | 5.171848e-06 | 0.003437 | 0.001504 | 3.644999e-08 | 4.049999e-09 | 0.000019 |
15 | 18 | 0.430855 | 0.455677 | 0.064554 | 0.040505 | 0.003374 | 4.104356e-06 | 0.003478 | 0.001534 | 2.892655e-08 | 3.214061e-09 | 0.000020 |
16 | 19 | 0.429875 | 0.456047 | 0.064807 | 0.040804 | 0.003366 | 3.298614e-06 | 0.003514 | 0.001562 | 2.324787e-08 | 2.583096e-09 | 0.000021 |
17 | 20 | 0.428996 | 0.456378 | 0.065034 | 0.041074 | 0.003359 | 2.681243e-06 | 0.003547 | 0.001587 | 1.889678e-08 | 2.099642e-09 | 0.000021 |
18 | 21 | 0.428203 | 0.456675 | 0.065239 | 0.041318 | 0.003353 | 2.201783e-06 | 0.003577 | 0.001610 | 1.551766e-08 | 1.724184e-09 | 0.000022 |
19 | 22 | 0.427483 | 0.456944 | 0.065426 | 0.041540 | 0.003348 | 1.824862e-06 | 0.003605 | 0.001631 | 1.286120e-08 | 1.429023e-09 | 0.000022 |
20 | 23 | 0.426827 | 0.457187 | 0.065596 | 0.041743 | 0.003342 | 1.525255e-06 | 0.003630 | 0.001650 | 1.074964e-08 | 1.194405e-09 | 0.000023 |
21 | 24 | 0.426227 | 0.457408 | 0.065752 | 0.041929 | 0.003338 | 1.284688e-06 | 0.003653 | 0.001668 | 9.054180e-09 | 1.006020e-09 | 0.000023 |
22 | 25 | 0.425676 | 0.457611 | 0.065896 | 0.042100 | 0.003333 | 1.089734e-06 | 0.003674 | 0.001684 | 7.680190e-09 | 8.533544e-10 | 0.000024 |
23 | 26 | 0.425168 | 0.457798 | 0.066029 | 0.042258 | 0.003329 | 9.303971e-07 | 0.003694 | 0.001699 | 6.557223e-09 | 7.285803e-10 | 0.000024 |
24 | 27 | 0.424699 | 0.457969 | 0.066151 | 0.042405 | 0.003326 | 7.991469e-07 | 0.003712 | 0.001713 | 5.632202e-09 | 6.258002e-10 | 0.000024 |
25 | 28 | 0.424263 | 0.458128 | 0.066265 | 0.042540 | 0.003322 | 6.902460e-07 | 0.003729 | 0.001726 | 4.864694e-09 | 5.405215e-10 | 0.000025 |
26 | 29 | 0.423858 | 0.458275 | 0.066371 | 0.042667 | 0.003319 | 5.992793e-07 | 0.003745 | 0.001739 | 4.223581e-09 | 4.692868e-10 | 0.000025 |
27 | 30 | 0.423481 | 0.458412 | 0.066470 | 0.042785 | 0.003316 | 5.228164e-07 | 0.003760 | 0.001750 | 3.684689e-09 | 4.094099e-10 | 0.000025 |
df.reset_index()
df = pd.DataFrame.melt(df,
id_vars = 'Suits',
var_name = "Hand",
value_name = "Probability")
df
Suits | Hand | Probability | |
---|---|---|---|
0 | 3 | High Card | 0.532308 |
1 | 4 | High Card | 0.501177 |
2 | 5 | High Card | 0.482360 |
3 | 6 | High Card | 0.470004 |
4 | 7 | High Card | 0.461324 |
... | ... | ... | ... |
303 | 26 | Five-of-a-Kind | 0.000024 |
304 | 27 | Five-of-a-Kind | 0.000024 |
305 | 28 | Five-of-a-Kind | 0.000025 |
306 | 29 | Five-of-a-Kind | 0.000025 |
307 | 30 | Five-of-a-Kind | 0.000025 |
308 rows × 3 columns
df.Hand.unique().tolist()
['High Card', 'Pair', 'Two Pair', 'Three-of-a-Kind', 'Straight', 'Flush', 'Full House', 'Four-of-a-Kind', 'Straight Flush', 'Royal Flush', 'Five-of-a-Kind']
plot1 = sns.lmplot(x ='Suits',
y = 'Probability',
data = df,
hue = 'Hand',
fit_reg = False,
palette = 'viridis',
height = 6,
aspect = 2,
scatter_kws = {"s": 75} )
#Title setup.
plt.title('Probabilities of Hands with N Suits', fontsize = 24)
#X-axis setup.
plt.xlabel('Suits', fontsize = 22)
#Y-axis setup.
plt.ylabel('Probability', fontsize = 22)
plt.tick_params(axis = 'both', which = 'major', labelsize = 18)
plt.show()
plot1.savefig("2023.03.17 Classic1.png")
plot2 = sns.lmplot(x ='Suits',
y = 'Probability',
data = df.loc[df.Hand.isin(['Straight', 'Full House'])],
hue = 'Hand',
fit_reg=False,
palette = 'viridis',
height = 6,
aspect = 2,
scatter_kws = {"s": 75} )
#Title setup.
plt.title('Probabilities of Hands with N Suits', fontsize = 24)
#X-axis setup.
plt.xlabel('Suits', fontsize = 22)
#Y-axis setup.
plt.ylabel('Probability', fontsize = 22)
plt.tick_params(axis = 'both', which = 'major', labelsize = 18)
plt.show()
plot2.savefig("2023.03.17 Classic2.png")