Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. from scipy.special import binom
  2. from collections import defaultdict
  3. import random
  4. from itertools import combinations
  5.  
  6.  
  7. def terrorists(n, p, nh, nd):
  8. a = defaultdict(list)
  9. b = defaultdict(int)
  10. for person in range(n):
  11. for day in range(nd):
  12. sleeps = random.uniform(0, 1)
  13. if sleeps <= p:
  14. hotel = random.randrange(0, nh)
  15. a[(day, hotel)].append(person)
  16. for value in a.values():
  17. for person1, person2 in combinations(value, 2):
  18. b[(min(person1, person2), max(person1, person2))] += 1
  19. for value in b.values():
  20. if value > 1:
  21. print()
  22. print()
  23.  
  24.  
  25. def theoritical_terrorists(n, p, nh, nd):
  26. return int(binom(n, 2) * binom(nd, 2) * p ** 2 * 1 / nh)
  27.  
  28.  
  29. def ex1():
  30. n = 10**4
  31. p = 0.1
  32. nh = 10**2
  33. nd = 10**2
  34. # print(theoritical_terrorists(n, p, nh, nd))
  35. terrorists(n, p, nh, nd)
  36.  
  37.  
  38. if __name__ == '__main__':
  39. ex1()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement