En 16800 simulaciones cuantas veces se recibe exactamente la misma mano

Escenario

En 16800 simulaciones cuantas veces se recibe exactamente la misma mano


Resultados

El escenario anterior se corrió 168 veces sin ningún resultado, luego se volvió.a correr 1680 veces y tampoco arrojó ningún resultado, finalmente se corrió 16.800 veces, se obtuvo 216 ocurrencias lo que representa 0,12%


¿Pasa mucho?



Código python para esta simulación


mport numpy as np
from collections import Counter

num_simulations = 16800
num_players = 4
pieces_per_player = 7
all_simulations_player_hands = []

# Re-run simulations to populate all_simulations_player_hands
for simulation_num in range(num_simulations):
# Re-initialize the full set of 28 domino pieces
domino_pieces_full = []
for i in range(7):
for j in range(i, 7):
domino_pieces_full.append((i, j))

# Shuffle the domino pieces
np.random.shuffle(domino_pieces_full)

current_simulation_hands = []
start_index = 0

# Distribute pieces to players
for _ in range(num_players):
player_hand = domino_pieces_full[start_index : start_index + pieces_per_player]
current_simulation_hands.append(player_hand)
start_index += pieces_per_player

# Store the hands for the current simulation
all_simulations_player_hands.append(current_simulation_hands)

print(f"Simulaciones completadas: {num_simulations}.")
print(f"Total de simulaciones almacenadas: {len(all_simulations_player_hands)}\n")

player_one_hands_canonical = []

# Convert each of Player One's hands to a canonical (sortable and hashable) form
for simulation_hands in all_simulations_player_hands:
p1_hand = simulation_hands[0] # Player One's hand

# Sort pieces within the hand, then sort the hand itself
# This ensures that hands with the same pieces, regardless of original order, are identical
canonical_hand = tuple(sorted(tuple(sorted(piece)) for piece in p1_hand))
player_one_hands_canonical.append(canonical_hand)

# Count the occurrences of each unique canonical hand
hand_counts = Counter(player_one_hands_canonical)

# Filter for hands that appeared more than once
duplicate_hands = {hand: count for hand, count in hand_counts.items() if count > 1}

total_duplicate_occurrences = sum(duplicate_hands.values())

print(f"De {num_simulations} simulaciones, el Jugador Uno recibió exactamente las mismas 7 fichas en un total de {total_duplicate_occurrences} ocasiones.")
print(f"Manos duplicadas encontradas (ejemplos): {len(duplicate_hands)} manos únicas se repitieron.")
for hand, count in list(duplicate_hands.items())[:5]: # Mostrar hasta 5 ejemplos
print(f" Mano: {list(hand)}, Cantidad: {count}")


Mano: [(0, 0), (0, 5), (1, 4), (1, 5), (2, 5), (4, 4), (4, 5)], Cantidad: 2 Mano: [(0, 0), (0, 1), (0, 3), (0, 5), (1, 4), (1, 5), (3, 6)], Cantidad: 2 Mano: [(1, 1), (1, 2), (1, 6), (2, 5), (4, 4), (4, 5), (5, 5)], Cantidad: 2 Mano: [(1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 6), (4, 6)], Cantidad: 2 Mano: [(0, 1), (0, 5), (1, 4), (1, 6), (2, 5), (3, 3), (5, 6)], Cantidad: 2

Comments

Popular Posts