human
Count triplets from an array which can form quadratic equations with real roots | Function to count the number of triplets ( a , b , c ) Such that the equations ax ^ 2 + bx + c = 0 has real roots.
sort he array in ascending order.
store count of triplets ( a , b , c ) such that ax ^ 2 + bx + c = 0 has real roots.
base case.
Traverse the given array.
if value of a and c are equal to b.
increment a.
Decrement c.
condition for having real roots for a quadratic equation.
if b lies in between a and c.
update count.
update count.
increment a.
Decrement c.
for each pair two values are possible of a and c.
Driver code ;"
How can the above be solved in Python?
 Write me a code to count triplets from an array which can form quadratic equations with real roots and the other steps required?
assistant
#Here is code to count triplets from an array which can form quadratic equations with real roots and the other steps required.
 def getcount ( arr , N ) :
	arr . sort ( )
	count = 0
	if ( N < 3 ) :
		return 0
	for b in range ( 0 , N ) :
		a = 0
		c = N - 1
		d = arr [ b ] * arr [ b ] // 4
		while ( a < c ) :
			if ( a == b ) :
				a += 1
				continue
			if ( c == b ) :
				c -= 1
				continue
			if ( arr [ a ] * arr ) <= d :
				if ( a < b and b < c ) :
					count += c - a - 1
				else :
					count += c - a
				a += 1
			else :
				c -= 1
	return count * 2
arr = [ 3 , 6 , 10 , 13 , 21 ]
N = len ( arr )
/ * Function Call * /
print ( getcount ( arr , N ) )