Guest User

Untitled

a guest
Oct 22nd, 2019
92
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def ryad(n):
  2. """
  3. Считаем количество занятых мест в ряду
  4. """
  5. import random
  6. count=0
  7. all_seats = set(zip(range(n-1),range(1,n)))
  8. while len(all_seats)!=0:
  9. a = random.sample(all_seats,1)
  10. seat_copy = all_seats.copy()
  11. for i in seat_copy:
  12. #if (a[0][0]-i[0]==1 and a[0][1]-i[1]==1) or (i[0]-a[0][0]==1 and i[1]-a[0][1]==1):
  13. if (a[0][0]-i[0]==1 and a[0][1]-i[1]==1) or (i[0]-a[0][0]==1 and i[1]-a[0][1]==1):
  14. all_seats.discard(i)
  15. #print(a[0][0],a[0][1],i[0],i[1])
  16. all_seats.discard(a[0])
  17. count+=1
  18. return count
  19.  
  20. n=1000
  21. M=100
  22. count_all=0
  23. for _ in range(M):
  24. count_all+=ryad(n)
  25. print(1-((2*count_all)/(M*n)))
RAW Paste Data