Guest User

Untitled

a guest
Apr 9th, 2024
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. import random
  2. import math
  3.  
  4.  
  5. def game(first):
  6.     first_wins = 0
  7.     for i in range(first):
  8.         if random.random() >= 0.5:
  9.             first_wins += 1
  10.  
  11.     first_wins *= 2
  12.  
  13.     second = 2*first
  14.     second_wins = 0
  15.     for i in range(second):
  16.         if random.random() >= 0.5:
  17.             second_wins += 1
  18.  
  19.     if first_wins == second_wins:
  20.         return 0
  21.     elif first_wins > second_wins:
  22.         return 1
  23.     return 2
  24.  
  25.  
  26. def main():
  27.     n = 10
  28.     iterations = 100000
  29.     results = [0, 0, 0]
  30.     for i in range(iterations):
  31.         results[game(n)] += 1
  32.  
  33.     print("Simulacija")
  34.     print(f"Nerijeseno: {results[0]/iterations}")
  35.     print(f"Prvi: {results[1]/iterations}")
  36.     print(f"Drugi: {results[1]/iterations}")
  37.     print()
  38.  
  39.     sum = 0
  40.     for i in range(0, n+1):
  41.         sum += math.comb(n, i) * math.comb(2*n, 2*i)
  42.     draw = sum / 2**(3*n)
  43.     win = (1 - draw) / 2
  44.     print("Izracun")
  45.     print(f"Nerijeseno: {draw}")
  46.     print(f"Prvi: {win}")
  47.     print(f"Drugi: {win}")
  48.  
  49.  
  50. if __name__ == "__main__":
  51.     main()
Advertisement
Add Comment
Please, Sign In to add comment