Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from scipy.special import binom
- from collections import defaultdict
- import random
- from itertools import combinations
- def terrorists(n, p, nh, nd):
- a = defaultdict(list)
- b = defaultdict(int)
- for person in range(n):
- for day in range(nd):
- sleeps = random.uniform(0, 1)
- if sleeps <= p:
- hotel = random.randrange(0, nh)
- a[(day, hotel)].append(person)
- for value in a.values():
- for person1, person2 in combinations(value, 2):
- b[(min(person1, person2), max(person1, person2))] += 1
- for value in b.values():
- if value > 1:
- print()
- print()
- def theoritical_terrorists(n, p, nh, nd):
- return int(binom(n, 2) * binom(nd, 2) * p ** 2 * 1 / nh)
- def ex1():
- n = 10**4
- p = 0.1
- nh = 10**2
- nd = 10**2
- # print(theoritical_terrorists(n, p, nh, nd))
- terrorists(n, p, nh, nd)
- if __name__ == '__main__':
- ex1()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement