forked from vinay-kumar99/Hactoberfest2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
count.py
39 lines (28 loc) · 778 Bytes
/
count.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# possible triangles using brute
# Function to count all possible
# triangles with arr[] elements
def findNumberOfTriangles(arr, n):
# Count of triangles
count = 0
# The three loops select three
# different values from array
for i in range(n):
for j in range(i + 1, n):
# The innermost loop checks for
# the triangle property
for k in range(j + 1, n):
# Sum of two sides is greater
# than the third
if (arr[i] + arr[j] > arr[k] and
arr[i] + arr[k] > arr[j] and
arr[k] + arr[j] > arr[i]):
count += 1
return count
# Driver code
if __name__ == "__main__":
arr = [10, 21, 22, 100, 101, 200, 300]
size = len(arr)
# Function call
print("Total number of triangles possible is",
findNumberOfTriangles(arr, size))
#thank you