aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Brattlof <hello@bryanbrattlof.com>2020-12-11 18:35:18 -0500
committerBryan Brattlof <hello@bryanbrattlof.com>2020-12-11 18:35:18 -0500
commit0e96a4eaae7ff44d6639f2787f4ed73045e58027 (patch)
treee950e7ea476162f427c32e7cd2baff567cfbb09f
parent8382d94ed2ee504879b2e63e77cfe1caa4d90fb9 (diff)
downloadadvent-of-code-0e96a4eaae7ff44d6639f2787f4ed73045e58027.tar.gz
advent-of-code-0e96a4eaae7ff44d6639f2787f4ed73045e58027.tar.bz2
day 3.2 of Advent of Code 2020
-rw-r--r--2020/day03/readme.rst30
-rw-r--r--2020/day03/toboggan-trajectory.py20
2 files changed, 47 insertions, 3 deletions
diff --git a/2020/day03/readme.rst b/2020/day03/readme.rst
index f6acba6..962aa77 100644
--- a/2020/day03/readme.rst
+++ b/2020/day03/readme.rst
@@ -75,3 +75,33 @@ encounter 7 trees.
Starting at the top-left corner of your map and following a slope of right 3 and
down 1, how many trees would you encounter?
+
+Your puzzle answer was 207.
+
+The first half of this puzzle is complete! It provides one gold star: *
+
+Part Two
+########
+
+Time to check the rest of the slopes - you need to minimize the probability of a
+sudden arboreal stop, after all.
+
+Determine the number of trees you would encounter if, for each of the following
+slopes, you start at the top-left corner and traverse the map all the way to the
+bottom:
+
+ Right 1, down 1.
+ Right 3, down 1. (This is the slope you already checked.)
+ Right 5, down 1.
+ Right 7, down 1.
+ Right 1, down 2.
+
+In the above example, these slopes would find 2, 7, 3, 4, and 2 tree(s)
+respectively; multiplied together, these produce the answer 336.
+
+What do you get if you multiply together the number of trees encountered on each
+of the listed slopes?
+
+our puzzle answer was 2655892800.
+
+Both parts of this puzzle are complete! They provide two gold stars: **
diff --git a/2020/day03/toboggan-trajectory.py b/2020/day03/toboggan-trajectory.py
index 41bf35b..b8eb267 100644
--- a/2020/day03/toboggan-trajectory.py
+++ b/2020/day03/toboggan-trajectory.py
@@ -1,4 +1,5 @@
from typing import List
+import math
EXAMPLE = [
'..##.......',
@@ -14,15 +15,15 @@ EXAMPLE = [
'.#..#...#.#',
]
-def encounters(inputs: List[str]) -> int:
+def encounters(inputs: List[str], right: int = 3, down: int = 1) -> int:
"""return number of tree encounters"""
trees, row, col = 0, 0, 0
repeats = len(inputs[0])
while row < len(inputs):
if inputs[row][col % repeats] == '#':
trees += 1
- row += 1
- col += 3
+ row += down
+ col += right
return trees
trees = encounters(EXAMPLE)
@@ -33,3 +34,16 @@ with open('data/slope.txt') as f:
trees = encounters(slope)
print(f'encounters: {trees}')
+
+# Part Two
+
+permutations = (
+ (1, 1),
+ (3, 1),
+ (5, 1),
+ (7, 1),
+ (1, 2)
+)
+
+print('\nProduct:')
+print(math.prod([encounters(slope, *version) for version in permutations]))