The problem is in section Reductio ad absurdum and indirect proof in How to Solve It:
White numbers using each of the the digits exactly once so that the sum of the numbers is exactly 100.
Here is the program to exhaust all sums:
sum_set = set()
numbers = set(range(0, 10))
def append_sum(sum):
global sum_set, numbers
l = len(numbers)
if l == 0:
sum_set.add(sum)
return
i = next(iter(numbers))
if l == 1:
sum_set.add(sum + i)
return
numbers.remove(i)
append_sum(sum + i)
for j in list(numbers):
numbers.remove(j)
append_sum(sum + i * 10 + j)
append_sum(sum + j * 10 + i)
numbers.add(j)
numbers.add(i)
append_sum(0)
sum_list = list(sum_set)
sum_list.sort()
print(sum_list)
Actually, all sums are divisible by 9, which can be easily proved by Divisibility Rule.