mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Solutions to day 17.
This commit is contained in:
20
day-17/input.txt
Normal file
20
day-17/input.txt
Normal 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
37
day-17/solution.py
Normal 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())])
|
||||
Reference in New Issue
Block a user