Advertisement
icarussiano

simulazione

Mar 18th, 2024
558
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. from random import choice
  2. N = 1000000
  3. def occurences(sub, string):
  4.     return sum(1 for i in range(len(string)) if string.startswith(sub, i))
  5. seqs = [''.join(choice(['T', 'C']) for _ in range(100)) for _ in range(N)]
  6. counts = [(seq.count('TC'), occurences('CC',seq)) for seq in seqs]
  7. alice_wins = sum(b>a for a,b in counts)
  8. bob_wins = sum(b<a for a,b in counts)
  9. eq = N - alice_wins - bob_wins
  10. print(f'Alice: {alice_wins/N*100}%')
  11. print(f'Bob: {bob_wins/N*100}%')
  12. print(f'Parità: {eq/N*100}%')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement