# Triangle = the sum of any two values (sides) > than the third value (third side)
# A + B > C
# B + C > A
# C + A > B
def CountTriangles(lst) :
size = len(lst)
count = 0
i = 0
while (i < size) :
j = i + 1
while (j < size) :
k = j + 1
while (k < size) :
if (lst[i] + lst[j] > lst[k] and lst[i] + lst[k] > lst[j] and lst[k] + lst[j] > lst[i]) :
count += 1
print(str(lst[i]) + " + " + str(lst[j]) + " > " + str(lst[k]) + " | ", end ="")
print(str(lst[i]) + " + " + str(lst[k]) + " > " + str(lst[j]) + " | ", end ="")
print(str(lst[k]) + " + " + str(lst[j]) + " > " + str(lst[i]))
k += 1
j += 1
i += 1
return count
lst = [120, 80, 13, 16, 9, 14, 19]
total_triangles = CountTriangles(lst)
print("Total triangles : " + str(total_triangles))
'''
run:
13 + 16 > 9 | 13 + 9 > 16 | 9 + 16 > 13
13 + 16 > 14 | 13 + 14 > 16 | 14 + 16 > 13
13 + 16 > 19 | 13 + 19 > 16 | 19 + 16 > 13
13 + 9 > 14 | 13 + 14 > 9 | 14 + 9 > 13
13 + 9 > 19 | 13 + 19 > 9 | 19 + 9 > 13
13 + 14 > 19 | 13 + 19 > 14 | 19 + 14 > 13
16 + 9 > 14 | 16 + 14 > 9 | 14 + 9 > 16
16 + 9 > 19 | 16 + 19 > 9 | 19 + 9 > 16
16 + 14 > 19 | 16 + 19 > 14 | 19 + 14 > 16
9 + 14 > 19 | 9 + 19 > 14 | 19 + 14 > 9
Total triangles : 10
'''