""" Exact probability and cost model for four EE88 articles that share the same underlying mathematics of the Vietnamese lo/de market: 1. "Soi cau bach thu lo" (post 814) 2. "Lo bach thu khung 2 ngay" (post 812) 3. "Kinh nghiem danh 3 cang" (post 841) 4. "Tu lo kho" (post 842) EVERY FIGURE IN THOSE ARTICLES IS PRODUCED BY THIS SCRIPT. No simulation, no sampling. Rational arithmetic (fractions.Fraction) and exact combinatorial identities only, so the output is reproducible bit for bit on any machine with Python 3.8+. THE MODEL --------- * Xo so kien thiet Mien Bac (XSMB) draws 27 prize levels per day (giai Dac biet through giai Bay). Each level contributes one "lo" - its last two digits (00..99). All 27 draws are independent. * Xo so kien thiet Mien Nam / Mien Trung (XSMN / XSMT) use 9 prize levels, i.e. 18 "lo" per day. * "Lo" on one number wins once for every time that number appears among the day's lo. E[so lan ve] = n_lo * 0.01 exactly. * "De" is the last two digits of the single giai Dac biet. P(thang) = 1/100 exactly, every day, forever. * "Bach thu lo" = bet on ONE number for the lo game. Same payout as lo, but the bet is a single point, so the payout is per appearance. * "Bach thu khung 2 ngay" = hold ONE number across TWO consecutive draws. The number only has to come up AT LEAST ONCE in the whole frame - that is what "bach thu" (white dove) means. The frame opens 2 x 27 = 54 lo in XSMB, so P(trung) = 1 - (99/100)^54 = 41,8834% This is a UNION over the frame's 54 lo, not a conjunction of two daily events. A conjunction (the number must appear on day 1 AND again on day 2) would give (1-(99/100)^27)^2 = 5,6481%, but that is a different bet - "bach thu lien ngay" - and it is not what the articles on this site describe. The articles' 41,8834% figure and this script's figure must agree, so the union model is the one used throughout. The payout is per APPEARANCE (per "n hay"), exactly as for a plain lo bet: E[số nháy] = 54 x 1/100 = 0,54, so the EV of the frame is 0,54 x 80.000 - 2 x 23.000 = -2.800đ, and the loss rate is the same -6,0870% per 1.000đ of stake as a single day's lo. * "3 cang" (3 cang) = the last three digits of the giai Dac biet. P(trung) = 1/1000 exactly. * "Tu lo kho" = a FOUR-digit number whose digits are a PERMUTATION of a chosen 4-digit set. The "kho" variant covers every distinct permutation of that set. The script enumerates the permutations exactly with a multinomial coefficient. PAYOUTS USED ------------ These differ between bookmakers, regions and channels (traditional ghi de versus online). The script states the assumption on every output line so a reader can recompute with their own numbers: lo / bach thu lo : stake 23,000 VND, pays 80,000 VND per point de : stake 1,000 VND, pays 70,000 VND 3 cang : stake 1,000 VND, pays 920,000 VND (1:920) tu lo : stake 1,000 VND, pays 70,000 VND (1:70) The 3 cang figure of 1:920 is the market-standard ratio: a 3-digit bet pays 920x the stake, so P = 1/1000 and RTP = 920/1000 = 92,00%. The tu lo figure of 1:70 is the market-standard ratio for a four-digit permutation bet. IMPORTANT: these payout ratios differ between bookmakers, regions and channels. The script states the assumption it uses on every line so a reader can recompute with their own numbers. Run: python3 lo-de-nhom-bach-thu-3cang-tu-lo-math.txt """ from fractions import Fraction from math import comb, factorial # --------------------------------------------------------------------------- # Constants # --------------------------------------------------------------------------- LO_PER_DAY_MB = 27 # lo drawn per XSMB day (DB -> giai Bay) LO_PER_DAY_MN = 18 # lo drawn per XSMN/XSMT day TOTAL_TWO_DIGIT = 100 # 00..99 TOTAL_THREE_DIGIT = 1000 # 000..999 # (label, stake, payout-per-point) BETS = { "lo": (23000, 80000), "de": (1000, 70000), "3 cang": (1000, 920000), "tu lo": (1000, 70000), } FAILURES = [] def check(label, computed, expected, tol=Fraction(1, 100000)): """Compare a computed value against a reference value.""" ok = abs(computed - expected) < tol if not ok: FAILURES.append(label) status = "MATCH" if ok else "MISMATCH" print(f" {label:<44} {float(computed):>13.6%} reference {float(expected):>10.4%} {status}") # --------------------------------------------------------------------------- # Core probabilities # --------------------------------------------------------------------------- def p_number_appears_at_least_once(n_lo=LO_PER_DAY_MB): """P(a specific 2-digit number appears in at least one of the n lo). Each lo is an independent uniform draw from 00..99, so a specific number misses a given lo with probability 99/100. Over n_lo draws the chance of never appearing is (99/100)^n_lo. """ return 1 - Fraction(99, 100) ** n_lo def expected_hits(n_lo=LO_PER_DAY_MB): """E[number of times one specific number appears] = n_lo * 1/100.""" return Fraction(n_lo, 100) def p_bach_thu_khung_n_ngay(n_lo=LO_PER_DAY_MB, n_days=2): """P(a held number appears AT LEAST ONCE in an n-day bach thu frame). The frame opens n_days * n_lo lo in total, and the number only has to come up once. So this is a UNION over the whole frame: P = 1 - (99/100)^(n_lo * n_days) NOT a conjunction. A conjunction - the number must appear on day 1 AND again on day 2 - would be p_number_appears_at_least_once() ** n_days = 5,6481% for a 2-day XSMB frame. That is a different bet ("bach thu lien ngay"), it is not the one the articles on this site describe, and using it here would put the published script in conflict with the 41,8834% that posts 812, 814, 831 and 850 all publish. All days must use the SAME lottery: a single number cannot appear in XSMB on day 1 and XSMN on day 2. """ return p_number_appears_at_least_once(n_lo * n_days) def p_3_cang(): """P(a specific 3-digit number equals the last 3 digits of giai Dac biet).""" return Fraction(1, TOTAL_THREE_DIGIT) def distinct_permutations(digits): """Number of distinct orderings of a multiset of digits. Multinomial coefficient: n! / (c1! * c2! * ...). """ counts = {} for d in digits: counts[d] = counts.get(d, 0) + 1 den = 1 for c in counts.values(): den *= factorial(c) return Fraction(factorial(len(digits)), den) def p_tu_lo(digits): """P(a tu lo bet on the given digit multiset wins). The bet covers every distinct permutation of the digit multiset. The special prize's last three digits must therefore have exactly that multiset. P = (number of covered permutations) * P(a specific 3-digit string is the special prize's last three digits). """ covered = distinct_permutations(digits) return covered * Fraction(1, TOTAL_THREE_DIGIT) def rtp(p_win, stake, payout): """Return-to-player over the long run.""" return p_win * payout / stake # --------------------------------------------------------------------------- # Report # --------------------------------------------------------------------------- def main(): print("=" * 80) print("XAC SUAT LO DE - NHOM BACH THU LO / KHUNG 2 NGAY / 3 CANG / TU LO") print("Mo hinh: XSMB 27 lo/ngay, XSMN/XSMT 18 lo/ngay, moi lo 2 so cuoi") print("=" * 80) p_ge1_mb = p_number_appears_at_least_once(LO_PER_DAY_MB) p_ge1_mn = p_number_appears_at_least_once(LO_PER_DAY_MN) print("\n[1] XAC SUAT CO BAN") check("P(so lo cu the ve >= 1 lan) - Mien Bac", p_ge1_mb, Fraction(23766, 100000), Fraction(1, 100000)) check("P(so lo cu the ve >= 1 lan) - Mien Nam", p_ge1_mn, Fraction(16549, 100000), Fraction(1, 100000)) print(f" E[so lan 1 so lo ve] mien Bac = {float(expected_hits(LO_PER_DAY_MB)):.4f}") print(f" E[so lan 1 so lo ve] mien Nam = {float(expected_hits(LO_PER_DAY_MN)):.4f}") print(f" P(de trung, 1 so) = {float(Fraction(1, 100)):.4%} (1/100)") print(f" P(3 cang trung, 1 bo) = {float(p_3_cang()):.4%} (1/1000)") print("\n[2] BACH THU LO - XAC SUAT VA CHI PHI") stake, pay = BETS["lo"] e_hits_mb = expected_hits(LO_PER_DAY_MB) r_lo = rtp(e_hits_mb, stake, pay) ev = e_hits_mb * pay - stake print(f" lo 23.000d/diem, an 80.000d/nhay") print(f" E[nhay/ngay] = {float(e_hits_mb):.4f}") print(f" RTP lo = {float(r_lo):.2%}") print(f" EV/ngay = {float(ev):,.0f} d") print(f" P(1 so ve >= 1 lan/ngay) mien Bac = {float(p_ge1_mb):.4%}") print(f" P(1 so ve >= 1 lan/ngay) mien Nam = {float(p_ge1_mn):.4%}") check("RTP lo = 80.000 x 0,27 / 23.000", r_lo, Fraction(21600, 23000)) print("\n[3] BACH THU KHUNG N NGAY (UNION: con so can ve it nhat MOT lan trong khung)") p2 = p_bach_thu_khung_n_ngay(LO_PER_DAY_MB, 2) p3 = p_bach_thu_khung_n_ngay(LO_PER_DAY_MB, 3) p5 = p_bach_thu_khung_n_ngay(LO_PER_DAY_MB, 5) print(f" {'khung':<12}{'so lo':>8}{'P(trung)':>16}{'1 trong':>12}{'E[nhay]':>10}{'chi phi':>14}{'EV/khung':>12}") for n, p in ((2, p2), (3, p3), (5, p5)): n_lo = n * LO_PER_DAY_MB e_nhaya = Fraction(n_lo, 100) ev_frame = e_nhaya * BETS["lo"][1] - n * BETS["lo"][0] print(f" {str(n)+' ngay':<12}{n_lo:>8}{float(p):>15.6%}{float(1/p):>12,.2f}" f"{float(e_nhaya):>10.2f}{float(n*BETS['lo'][0]):>13,.0f} d{float(ev_frame):>11,.0f} d") # The union model must reproduce the 41,8834% that posts 812 / 814 / 831 / 850 publish. check("P(khung 2 ngay XSMB) = 41,8834%", p2, Fraction(418834, 1000000), Fraction(1, 1000000)) # And it must NOT be the conjunction value, which is a different bet. assert p2 != p_ge1_mb * p_ge1_mb, "khung 2 ngay phai la UNION, khong phai conjunction" print(" khung 2 ngay = UNION tren 54 lo (khong phai conjunction) OK") print("\n[4] 3 CANG") stake3, pay3 = BETS["3 cang"] r3 = rtp(p_3_cang(), stake3, pay3) ev3 = p_3_cang() * pay3 - stake3 print(f" P(trung) = {float(p_3_cang()):.4%} (1/1000)") print(f" RTP = {float(r3):.2%}") print(f" EV/cuoc = {float(ev3):,.0f} d") print(f" 100 ky khong trung: {float((1-p_3_cang())**100):.4%}") print(f" 1.000 ky khong trung: {float((1-p_3_cang())**1000):.6%}") check("RTP 3 cang = 920 x (1/1000)", r3, Fraction(92, 100)) print("\n[5] TU LO KHO - XAC SUAT THEO TAP CHU SO") print(f" {'tap chu so':<16}{'so hoan vi':>14}{'P(trung)':>16}{'1 trong':>16}") samples = [ (1, 2, 3, 4), (1, 1, 2, 3), (1, 1, 1, 2), (0, 0, 0, 1), (2, 5, 7, 9), (1, 1, 1, 1), (1, 2, 3, 5), (7, 7, 8, 9), ] for d in samples: n = int(distinct_permutations(d)) p = p_tu_lo(d) print(f" {''.join(map(str, d)):<16}{n:>14}{float(p):>15.6%}{float(1/p):>16,.1f}") check("P(tu lo 4 so khac nhau) = 24/1000", p_tu_lo((1, 2, 3, 4)), Fraction(24, 1000)) check("P(tu lo 1 so lap 2 lan) = 12/1000", p_tu_lo((1, 1, 2, 3)), Fraction(12, 1000)) check("P(tu lo 1 so lap 3 lan) = 4/1000", p_tu_lo((1, 1, 1, 2)), Fraction(4, 1000)) check("P(tu lo 4 so giong nhau) = 1/1000", p_tu_lo((1, 1, 1, 1)), Fraction(1, 1000)) print("\n[6] CHI PHI THEO THOI GIAN") print(f" {'hinh thuc':<36}{'EV/ngay':>14}{'EV 30 ngay':>16}{'EV 365 ngay':>18}") # Bach thu khung 2 ngay: EV per FRAME. The frame is two daily draws, # so its EV is the sum of the two daily EVs - it does NOT multiply by # the frame's hit probability. (Multiplying by p2 is the bug this # section used to carry: it produced -41.482đ per frame, which # implied an RTP of 9,82% for a bet the market pays at 93,91%.) ev_bach_thu_frame = Fraction(2 * LO_PER_DAY_MB, 100) * BETS["lo"][1] - 2 * BETS["lo"][0] rows = [ ("lo 1 con (mien Bac, 27 lo)", e_hits_mb * BETS["lo"][1] - BETS["lo"][0]), ("lo 1 con (mien Nam, 18 lo)", expected_hits(LO_PER_DAY_MN) * BETS["lo"][1] - BETS["lo"][0]), ("de 1 so", Fraction(1, 100) * BETS["de"][1] - BETS["de"][0]), ("3 cang 1 bo", p_3_cang() * BETS["3 cang"][1] - BETS["3 cang"][0]), ("bach thu khung 2 ngay / ngay", ev_bach_thu_frame / 2), ] for label, ev_day in rows: print(f" {label:<36}{float(ev_day):>13,.0f} d{float(ev_day*30):>15,.0f} d{float(ev_day*365):>17,.0f} d") print() print(f" EV mot KHUNG bach thu 2 ngay = {float(ev_bach_thu_frame):,.0f} d") print(f" Tu le mat tren moi 1.000d von = {float(ev_bach_thu_frame / (2 * BETS['lo'][0])) * 100:.4f}%") assert ev_bach_thu_frame == 2 * (e_hits_mb * BETS["lo"][1] - BETS["lo"][0]), \ "EV khung 2 ngay phai bang 2 x EV mot ngay" print(" EV khung 2 ngay = 2 x EV mot ngay (ty le mat khong doi) OK") print("\n[7] NHAN CAM VOI GIA 1 DIEM LO") print(f" {'gia/diem':>10} {'RTP (an 80.000d)':>20} {'EV/cuoc':>14}") for price in (21700, 22500, 23000, 25000, 29000): r = rtp(e_hits_mb, price, 80000) evp = e_hits_mb * 80000 - price print(f" {price:>10,} {float(r):>19.2%} {float(evp):>13,.0f} d") print("\n[8] KIEM TRA TINH NHAT QUAN") for k in (1, 10, 20, 50, 90): cost = k * BETS["lo"][0] r = rtp(k * e_hits_mb, cost, BETS["lo"][1]) assert r == rtp(e_hits_mb, BETS["lo"][0], BETS["lo"][1]), "bao lo RTP phai bang lo" print(" bao lo k so: RTP khong doi theo k OK") # Khung 2 ngay = UNION tren 54 lo, khong phai (khung 1 ngay)^2. assert p_bach_thu_khung_n_ngay(LO_PER_DAY_MB, 2) == p_number_appears_at_least_once(54) assert p_bach_thu_khung_n_ngay(LO_PER_DAY_MB, 2) != p_ge1_mb * p_ge1_mb print(" khung 2 ngay = UNION tren 54 lo OK") # Ty le mat cua khung phai bang ty le mat cua mot ngay. rate_1d = (e_hits_mb * BETS["lo"][1] - BETS["lo"][0]) / BETS["lo"][0] rate_2d = ev_bach_thu_frame / (2 * BETS["lo"][0]) assert rate_1d == rate_2d, "ty le mat khung 2 ngay phai bang ty le mat 1 ngay" print(" ty le mat khung 2 ngay = ty le mat 1 ngay OK") # RTP cua khung phai bang RTP cua lo thuong. r_bach_thu = rtp(Fraction(54, 100), 2 * BETS["lo"][0], BETS["lo"][1]) assert r_bach_thu == rtp(e_hits_mb, BETS["lo"][0], BETS["lo"][1]), "RTP khung phai bang RTP lo" print(" RTP khung 2 ngay = RTP lo OK") assert distinct_permutations((1, 2, 3, 4)) == 24 assert distinct_permutations((1, 1, 2, 3)) == 12 assert distinct_permutations((1, 1, 1, 1)) == 1 assert sum(distinct_permutations(d) for d in [(1, 2, 3, 4)]) == 24 print(" so hoan vi phan biet OK") print("\n" + "=" * 80) if FAILURES: print("KET QUA: CO KIEM TRA KHONG KHOP -> " + ", ".join(FAILURES)) print("=" * 80) raise SystemExit(1) print("KET QUA: TAT CA KIEM TRA THAM CHIEU KHOP.") print("=" * 80) if __name__ == "__main__": main()