# tripleBirthday-q2
# Exs for Section 41, Q.2, P.151, P.272

import random

M = 365
N = 10000
P = 731 # must be a triple among P birthdays
x = [0]*M     # stores birthdays
y = [0]*P     # stores waiting times
for i in range(N):
  for j in range(M):
    x[j] = 0
  j = 0
  while True:   
    # samples the M birthdays until one
    # of them occurs for the 3rd time
    j = j+1
    r = random.randint(0,M-1)
    x[r] += 1
    if x[r] == 3:
      break
  y[j] += 1    # Waiting time for j increased

sum = 0
for i in range(P):
  sum += i*y[i]
print(f"{sum/N:.4f}")

