Problem 103

completed January 22, 2012

Comments

Not too hard, just wish it could have run faster.

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


last = 0
for a in combinations(range(19, 48), 7):
	a = set(a)
	if rule1(a) == True and rule2(a) == True:
		print a
		break