44 lines
726 B
Python
44 lines
726 B
Python
# Fill Input
|
|
|
|
input = ""
|
|
|
|
try:
|
|
with open("17.txt", 'r', encoding='utf-8') as file:
|
|
input += file.read()
|
|
except Exception as e:
|
|
print(f"An error occurred: {e}")
|
|
|
|
# Check if sum of permutation equal 150
|
|
def sum_equal_150(input, i):
|
|
sum = 0
|
|
for j in range(l):
|
|
if i & 1<<j:
|
|
sum += input[j]
|
|
if sum > 150:
|
|
return False
|
|
return sum == 150
|
|
|
|
# Reverse sort input
|
|
input= [ int(x) for x in input.split()]
|
|
input.sort(reverse=True)
|
|
|
|
l = len(input)
|
|
res1, res2, min_popcount = 0, 0, l
|
|
|
|
for i in range(2**l):
|
|
if not sum_equal_150(input, i):
|
|
continue
|
|
|
|
popcount = i.bit_count()
|
|
|
|
if popcount < min_popcount:
|
|
min_popcount = popcount
|
|
res2 = 0;
|
|
|
|
if popcount == min_popcount:
|
|
res2 += 1;
|
|
|
|
res1 += 1
|
|
|
|
print(res1, res2)
|