def increment(indices): i = 0 n = len(indices) while i < n: indices[i] += 1 if indices[i] < 2: return(True) indices[i] = 0 i += 1 return(False) def partitionArray(theArray): print("theArray: " + str(theArray) + "\n") # every element in 'theArray' will be in one of our # two partitions, 0 for the first partition, 1 for the second indices = [] n = len(theArray) for i in range(0, n): indices.append(0) found = False while not found: first = [] second = [] for i in range(0, n): if indices[i] == 0: first.append(theArray[i]) else: second.append(theArray[i]) theSum = sum(first) if theSum == sum(second): print(" first : " + str(first)) print(" second: " + str(second)) print(" sum : " + str(theSum)) found = True if not increment(indices): break if not found: print(" No partitions found") list = [ [ 36, 12, 36, 25, 26, 49, 39, 5 ], [ 44, 48, 45, 47, 8, 39, 2, 27, 47, 4, 42 ], [ 40, 37, 41, 41, 31, 47, 5, 49, 37, 6 ], [ 14, 7, 34, 40, 24, 33, 25, 46, 4, 1, 46 ], [ 26, 27, 2, 2, 0, 6, 37, 4, 29, 10, 8 ], [ 16, 25, 31, 23, 30, 23, 12, 24, 19, 21, 27, 11, 28, 20 ], [ 5, 22, 19, 11, 25, 25, 2, 14, 18, 24, 4, 43, 28 ], [ 47, 49, 45, 32, 41, 18, 7, 2, 49, 48, 18 ], [ 46, 44, 12, 29, 35, 24, 0, 43, 17, 23, 12, 38, 6, 5 ], [ 10, 29, 10, 4, 29, 38, 23, 37, 14, 47, 23, 16 ] ] for array in list: partitionArray(array) print()