Solutions to day 17.

This commit is contained in:
Bert Peters
2015-12-17 12:57:44 +01:00
parent 7c7878be2b
commit 4751945dc8
2 changed files with 57 additions and 0 deletions

20
day-17/input.txt Normal file
View File

@@ -0,0 +1,20 @@
33
14
18
20
45
35
16
35
1
13
18
13
50
44
48
6
24
41
30
42

37
day-17/solution.py Normal file
View File

@@ -0,0 +1,37 @@
from __future__ import print_function, division
import fileinput
from collections import defaultdict
buckets = []
for line in fileinput.input():
buckets.append(int(line))
def works(bucketCombination, target):
for idx, value in enumerate(buckets):
if bucketCombination % 2 == 1:
target -= value
bucketCombination = bucketCombination // 2
return target == 0
def ones(x):
n = 0
while x > 0:
if x % 2:
n += 1
x //= 2
return n
possible = defaultdict(lambda: 0)
for x in range(1 << len(buckets)):
if works(x, 150):
n = ones(x)
possible[n] += 1
print(sum(possible[x] for x in possible), possible[min(possible.keys())])