diff --git a/day01/part2.py b/day01/part2.py index e32068e..77e6c0b 100644 --- a/day01/part2.py +++ b/day01/part2.py @@ -1,17 +1,21 @@ -import math +import operator +from functools import reduce items = (int(x.strip()) for x in open("input.txt")) values = {(2020, 3)} tree = dict() -def tree_up(idx, step=1, offset = 0): - print(idx, step) +def tree_up(idx, step=1, offset=0): nxt = tree[(idx, step)] if (idx, step) in tree else None appendix = [] if nxt is None else tree_up(nxt+idx, step=step+1, offset=idx) return [idx - offset] + appendix +def prod(iterable): + return reduce(operator.mul, iterable, 1) + + for item in items: tmp_values = set(values) for elem in values: @@ -21,12 +25,12 @@ for item in items: print("Found [{}]: Sum={}, Product={}".format( ", ".join(map(str, vals)), sum(vals), - math.prod(vals) + prod(vals) )) exit() elif new[0] < 0 or new[1] < 0: # target value too low or to many sums - continue + pass else: tree[new] = item tmp_values.add(new) diff --git a/python-aoc-2020.iml b/python-aoc-2020.iml index ec6b888..1e36f4d 100644 --- a/python-aoc-2020.iml +++ b/python-aoc-2020.iml @@ -2,7 +2,7 @@ - + @@ -11,6 +11,6 @@ - + \ No newline at end of file