human
Minimum elements to be inserted in Array to make adjacent differences equal | Function to find gcd of two numbers.
Function to calculate minimum numbers to be inserted to make equal differences between two consecutive elements.
Check if there is only one element in the array then answer will be 0.
Calculate difference between first and second element of array.
If there is only two elements in the array then gcd of differences of consecutive elements of array will be equal to difference of first and second element of the array.
Loop to calculate the gcd of the differences between consecutive elements of the array.
Loop to calculate the elements to be inserted.
Return the answer.
Driver code"
How can the above be solved in Python?
 What is a code to minimum elements to be inserted in Array to make adjacent differences equal and the other steps required?
assistant
#Here is code to minimum elements to be inserted in Array to make adjacent differences equal and the other steps required.
 def gcd ( a , b ) :
	if ( b == 0 ) :
		return a
	return gcd ( b , a % b )
def minimum_elements ( n , arr ) :
	if ( n < 3 ) :
		return 0
	ans = 0
	diff = arr [ 1 ] - arr [ 0 ]
	g = diff
	for i in range ( 2 , n ) :
		diff = arr [ i ] - arr [ i - 1 ]
		g = gcd ( g , diff )
	for i in range ( 1 , n ) :
		diff = arr [ i ] - arr [ i - 1 ]
		cnt = diff // g
		ans += ( cnt - 1 )
	return ans
arr = [ 1 , 5 , 8 , 10 , 12 , 16 ]
n = len ( arr )
print ( minimum_elements ( n , arr ) )