diff options
Diffstat (limited to 'day3/day3.py')
-rw-r--r-- | day3/day3.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/day3/day3.py b/day3/day3.py new file mode 100644 index 0000000..716dc5e --- /dev/null +++ b/day3/day3.py @@ -0,0 +1,35 @@ +from functools import reduce +from itertools import islice + + +def nth(iterable, n): + return next(islice(iter(iterable), n, n + 1)) + + +def mult(iterable): + return reduce(lambda x, y: x * y, iterable) + + +def count_trees(data, right, down): + return [nth(row, right * idx % len(row)) for idx, row in enumerate(data[::down])].count("#") + + +data = list(map(str.strip, open("input"))) + + +# Part 1 +down = 1 +right = 3 +print(count_trees(data, right, down)) + + +# Part 2 +slopes = [ + # R, D + [1, 1], + [3, 1], + [5, 1], + [7, 1], + [1, 2], +] +print(mult([count_trees(data, right, down) for right, down in slopes])) |