Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. from math import sqrt
  2. N = 10000000
  3. cnt = 0
  4. x = []
  5. y = []
  6. M = 0
  7. for _ in range(N):
  8. x1 = uniform(0,2)
  9. y1 = uniform(0,2)
  10. x2 = uniform(0,2)
  11. y2 = uniform(0,2)
  12. if (x2 - 1)**2 + (y2 - 1)**2 <= 1 and (x1 - 1)**2 + (y1 - 1)**2 <= 1:
  13. M += 1
  14. if sqrt((x2 - x1)**2 + (y2 - y1)**2) < 1:
  15. cnt += 1
  16.  
  17. print(cnt / M)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement