File size: 1,551 Bytes
6fc92ce
 
 
 
06c4228
6fc92ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
06c4228
 
 
 
 
 
6fc92ce
 
 
06c4228
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6fc92ce
 
 
06c4228
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import streamlit as st
import random
from collections import Counter

# Set up Streamlit app
st.set_page_config(page_title="Bầu Cua Tôm Cá", layout="centered")
st.title("Bầu Cua Tôm Cá")

# UI elements
shake_info = st.empty()
result_label = st.empty()

dice_faces = ["Bầu", "Cua", "Tôm", "Cá", "Gà", "Nai"]
default_faces = ["Cá", "Gà", "Nai"]
selected_faces = []

cols = st.columns(3)
for i, col in enumerate(cols):
    with col:
        selected_faces.append(st.radio(f"Chọn mặt {i+1}", dice_faces, index=dice_faces.index(default_faces[i])))

def predict_result():
    outcomes = ["Bầu", "Cua", "Tôm", "Cá", "Gà", "Nai"]
    results = []
    shake_count = 0

    while True:
        shake_count += 1
        results.append(random.choice(outcomes))
        result_counts = Counter(results)
        sorted_results = sorted(result_counts.items(), key=lambda x: x[1], reverse=True)

        if len(sorted_results) > 1:
            rank_1, rank_2 = sorted_results[:2]
            rank_1_pct = rank_1[1] / shake_count
            rank_2_pct = rank_2[1] / shake_count

            if (rank_1_pct - rank_2_pct) > 0.03:  # Chênh lệch > 3%
                break

    # Hiển thị kết quả
    result_text = f"Số lần lắc: {shake_count}\n\nKết quả:\n"
    for outcome, count in sorted_results:
        result_text += f"{outcome}: {count} ({count/shake_count:.2%})\n"

    result_label.text(result_text)
    shake_info.text(f"Tổng số lần lắc: {shake_count}")

# Buttons
if st.button("Lắc"):
    predict_result()