human
Number of Groups of Sizes Two Or Three Divisible By 3 | Program to find groups of 2 or 3 whose sum is divisible by 3.
Initialize groups to 0.
Increment group with specified remainder.
Return groups using the formula.
Driver code"
Solution in Python:
assistant
#Here is code to number of Groups of Sizes Two Or Three Divisible By 3 and the other steps required.
 def numOfCombinations ( arr , N ) :
	C = [ 0 , 0 , 0 ]
	for i in range ( N ) :
		C [ arr [ i ] % 3 ] = C [ arr [ i ] % 3 ] + 1
	return ( C [ 1 ] * C [ 2 ] + C [ 0 ] * ( C [ 0 ] - 1 ) / 2 + C [ 0 ] * ( C [ 0 ] - 1 ) * ( C [ 0 ] - 2 ) / 6 + C [ 1 ] * ( C [ 1 ] - 1 ) * ( C [ 1 ] - 2 ) / 6 + C [ 2 ] * ( C [ 2 ] - 1 ) * ( C [ 2 ] - 2 ) / 6 + C [ 0 ] * C [ 1 ] * C [ 2 ] )
arr1 = [ 1 , 5 , 7 , 2 , 9 , 14 ]
print ( int ( numOfCombinations ( arr1 , 6 ) ) )
arr2 = [ 3 , 6 , 9 , 12 ]
print ( int ( numOfCombinations ( arr2 , 4 ) ) )