human
Print combinations of distinct numbers which add up to give sum N | arr [ ] to store all the distinct elements index - next location in array num - given number reducedNum - reduced number.
Set to store all the distinct elements.
Base condition.
Iterate over all the elements and store it into the set.
Calculate the sum of all the elements of the set.
Compare whether the sum is equal to n or not , if it is equal to n print the numbers.
Find previous number stored in the array.
Store all the numbers recursively into the arr [ ].
Function to find all the distinct combinations of n.
Driver code"
Solution in Python:
assistant
#Here is code to print combinations of distinct numbers which add up to give sum N and the other steps required.
 def findCombinationsUtil ( arr , index , n , red_num ) :
	s = set ( )
	sum = 0
	if ( red_num < 0 ) :
		return
	if ( red_num == 0 ) :
		for i in range ( index ) :
			s . add ( arr [ i ] )
		for itr in s :
			sum = sum + ( itr )
		if ( sum == n ) :
			for i in s :
				print ( i , end = " ▁ " )
			print ( " " , ▁ end ▁ = ▁ " " )
			return
	if ( index == 0 ) :
		prev = 1
	else :
		prev = arr [ index - 1 ]
	for k in range ( prev , n + 1 , 1 ) :
		arr [ index ] = k
		findCombinationsUtil ( arr , index + 1 , n , red_num - k )
def findCombinations ( n ) :
	a = [ 0 for i in range ( n + 1 ) ]
	findCombinationsUtil ( a , 0 , n , n )
if __name__ == ' _ _ main _ _ ' :
	n = 7
	findCombinations ( n )