Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import choice
- N = 1000000
- def occurences(sub, string):
- return sum(1 for i in range(len(string)) if string.startswith(sub, i))
- seqs = [''.join(choice(['T', 'C']) for _ in range(100)) for _ in range(N)]
- counts = [(seq.count('TC'), occurences('CC',seq)) for seq in seqs]
- bob_counts=sorted([x for x,y in counts])
- alice_counts=sorted([y for x,y in counts])
- import matplotlib.pyplot as plt
- import numpy as np
- from collections import Counter
- bob_mean, bob_median = np.mean(bob_counts), np.median(bob_counts)
- alice_mean, alice_median = np.mean(alice_counts), np.median(alice_counts)
- bob_counts = Counter(bob_counts)
- bob_counts_keys, bob_counts_values = list(bob_counts.keys()), list(bob_counts.values())
- alice_counts = Counter(alice_counts)
- alice_counts_keys, alice_counts_values = list(alice_counts.keys()), list(alice_counts.values())
- label_bob = f'Bob mean: {bob_mean:.2f}, median: {bob_median:.2f}'
- label_alice = f'Alice mean: {alice_mean:.2f}, median: {alice_median:.2f}'
- plt.plot(bob_counts_keys, bob_counts_values, label=label_bob)
- plt.plot(alice_counts_keys, alice_counts_values, label=label_alice)
- plt.legend()
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement