Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def ryad(n):
- """
- Считаем количество занятых мест в ряду
- """
- import random
- count=0
- all_seats = set(zip(range(n-1),range(1,n)))
- while len(all_seats)!=0:
- a = random.sample(all_seats,1)
- seat_copy = all_seats.copy()
- for i in seat_copy:
- #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):
- 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):
- all_seats.discard(i)
- #print(a[0][0],a[0][1],i[0],i[1])
- all_seats.discard(a[0])
- count+=1
- return count
- n=1000
- M=100
- count_all=0
- for _ in range(M):
- count_all+=ryad(n)
- print(1-((2*count_all)/(M*n)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement