Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import math
- def game(first):
- first_wins = 0
- for i in range(first):
- if random.random() >= 0.5:
- first_wins += 1
- first_wins *= 2
- second = 2*first
- second_wins = 0
- for i in range(second):
- if random.random() >= 0.5:
- second_wins += 1
- if first_wins == second_wins:
- return 0
- elif first_wins > second_wins:
- return 1
- return 2
- def main():
- n = 10
- iterations = 100000
- results = [0, 0, 0]
- for i in range(iterations):
- results[game(n)] += 1
- print("Simulacija")
- print(f"Nerijeseno: {results[0]/iterations}")
- print(f"Prvi: {results[1]/iterations}")
- print(f"Drugi: {results[1]/iterations}")
- print()
- sum = 0
- for i in range(0, n+1):
- sum += math.comb(n, i) * math.comb(2*n, 2*i)
- draw = sum / 2**(3*n)
- win = (1 - draw) / 2
- print("Izracun")
- print(f"Nerijeseno: {draw}")
- print(f"Prvi: {win}")
- print(f"Drugi: {win}")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment