Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Task 3B: Check String
- def check_string(coord, size, x_coord, y_coord):
- return abs(coord - x_coord) > size or abs(coord - y_coord) > size
- ### Task 3C: Mosquito Carlo
- from math import *
- from random import uniform
- def monte_carlo_mosquito(string_dist, size):
- coord = [0]
- a = string_dist
- while a <= 1:
- coord.append(round(a, 4))
- coord.append(round(-a, 4))
- a += string_dist
- total, hits = 0, 0
- for mosquito in range(100000):
- total += 1
- x, y = uniform(-1,1), uniform(-1, 1)
- if check_outside(size, x, y) == False:
- for i in coord:
- if check_string(i, size, x, y) == False:
- hits += 1
- break
- return hits / total, hits, total
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement