Problem 105

completed January 22, 2012

Comments

I can’t believe it was that easy. I basically just copied and pasted the code from problem 103. Ran in 15 seconds too.

Code

from itertools import *

def rule1(a):
	for i in range(1, len(a)/2+1):
		for A in combinations(a, i):
			for j in range(1, len(a)-len(A)+1):
				for B in combinations((set(a)-set(A)), j):
					if sum(list(A)) == sum(list(B)):
						return False
	return True

def rule2(a):
	for i in range(1, len(a)/2+1):
		for A in combinations(a, i):
			for j in range(1, len(a)-len(A)+1):
				for B in combinations((set(a)-set(A)), j):
					if len(A) > len(B) and sum(list(A)) < sum(list(B)):
						return False
					elif len(B) > len(A) and sum(list(B)) < sum(list(A)):
						return False
	return True

def S(a):
	return sum(list(a))


total = 0
for A in sets:
	if rule1(A) == True and rule2(A) == True:
		total += S(A)

print total