Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import random
- import math
- import matplotlib
- import matplotlib.pyplot as plt
- %matplotlib inline
- def acute(a, b, c):
- cosa = (a**2 - b**2 + c**2)/(2 * a * c)
- cosb = (b**2 - a**2 + c**2)/(2 * b * c)
- cosc = (b**2 - c**2 + a**2)/(2 * b * a)
- if cosa > 1 or cosa < -1 or cosb > 1 or cosb < -1 or cosc > 1 or cosc < -1:
- return False
- if (math.acos(cosa) < 1.5708) and (math.acos(cosb) < 1.5708) and (math.acos(cosc) < 1.5708):
- return True
- else:
- return False
- def triangle(N):
- n = 0
- for i in range(N):
- x = random()
- y = random()
- if x < y:
- a = x
- b = y - x
- c = 1 - y
- else:
- a = y
- b = x - y
- c = 1 - x
- # Condition:
- if b < a > c:
- if (a < b + c) and acute(a, b, c):
- n += 1
- elif (a < b > c) and acute(a, b, c):
- if b < a + c:
- n += 1
- else:
- if (c < a + c) and acute(a, b, c):
- n += 1
- return n/N
- N = 10000
- print("Answer:")
- print(triangle(N))
- x = [i for i in range(1, 10000, 100)]
- y1 = []
- for i in range(1, 1000, 10):
- y1.append(A(i))
- plt.plot(x[2:], y1[2:])
- plt.title('PLOT')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement