human
Count of acute , obtuse and right triangles with given sides | Find the number of acute , right , obtuse triangle that can be formed from given array ..
Finding the square of each element of array.
Sort the sides of array and their squares ..
x for acute triangles y for right triangles z for obtuse triangles.
Finding the farthest point p where a ^ 2 + b ^ 2 >= c ^ 2..
Finding the farthest point q where a + b > c ..
If point p make right triangle ..
All triangle between j and p are acute triangles . So add p - j - 1 in x ..
Increment y by 1..
All triangle between q and p are acute triangles . So add q - p in z ..
If no right triangle.
All triangle between j and p are acute triangles . So add p - j in x ..
All triangle between q and p are acute triangles . So add q - p in z ..
Driver Code"
Solution in Python:
assistant
#Here is code to count of acute , obtuse and right triangles with given sides and the other steps required.
 def findTriangle ( a , n ) :
	b = [ ]
	for i in range ( n ) :
		b . append ( a [ i ] * a [ i ] )
	a . sort ( )
	b . sort ( )
	x , y , z = 0 , 0 , 0
	for i in range ( n ) :
		p = i + 1
		q = i + 1
		for j in range ( i + 1 , n ) :
			while ( p < n - 1 and b [ i ] + b [ j ] >= b [ p + 1 ] ) :
				p += 1
			q = max ( q , p )
			while ( q < n - 1 and a [ i ] + a [ j ] > a [ q + 1 ] ) :
				q += 1
			if ( b [ i ] + b [ j ] == b [ p ] ) :
				x += max ( p - j - 1 , 0 )
				y += 1
				z += q - p
			else :
				x += max ( p - j , 0 )
				z += q - p
	print ( " Acute ▁ Triangle : " , x )
	print ( " Right ▁ Triangle : " , y )
	print ( " Obtuse ▁ Triangle : " , z )
if __name__ == " _ _ main _ _ " :
	arr = [ 2 , 3 , 9 , 10 , 12 , 15 ]
	n = len ( arr )
	findTriangle ( arr , n )