<jupyter_start><jupyter_text>Day 3: Toboggan Trajectoryhttps://adventofcode.com/2020/day/3 Part 1<jupyter_code>from pathlib import Path

INPUTS = Path('input.txt').resolve().read_text().strip().split('\n')
TREE = '#'

def get_trees_encountered(right, down=1):
    """For the given INPUTS and the slope determined by right and down,
    returns the total number of trees encountered on that slope.
    """
    encountered = 0
    pos = 0

    # To account for down, use the `step` argument in slice notation for the INPUTS list.
    for line in INPUTS[::down]:
        # According to instructions, the pattern repeats to the right.
        # This means we can take our cumulatively `pos` and wrap it around again.
        # To determine that real position, use the cumulative position % (mod)
        # the length of that line:
        real_pos = pos % len(line)

        # Now we can test that position for a tree:
        if line[real_pos] == TREE:
            encountered += 1
        
        # To get a cumulative position to the right, we have to keep adding
        # the `right` value to our running position.
        # As noted above, the "down" movement is accounted for by the loop itself
        # and the `step` argument of the slice.
        pos += right
    
    return encountered

# With that function set up, we can simply return our result:
print(f"{get_trees_encountered(right=3, down=1)} trees encountered going 3 right, 1 down.")<jupyter_output>153 trees encountered going 3 right, 1 down.<jupyter_text>Part 2<jupyter_code># This essentially uses the same code as the first part, but with multiple slope arguments
# and a cumulative product at the end. Simple enough.

# Set up the slopes we need as a list of (right, down) tuples
slopes = [
    (1, 1),
    (3, 1),
    (5, 1),
    (7, 1),
    (1, 2),
]
# Use a base multiplier of 1 that we'll cumulatively *= encountered trees into
multiplier = 1

# Now, simply iterate on our slopes and calculate them.
for right, down in slopes:
    encountered = get_trees_encountered(right=right, down=down)
    print(f"{encountered} trees enountered going {right} right, {down} down.")

    # Cumulatively multiply the encountered trees to our total product.
    multiplier *= encountered

# Now output that product for our final answer.
print(f"\nMultiplied together, the answer is: {multiplier}")<jupyter_output>66 trees enountered going 1 right, 1 down.
153 trees enountered going 3 right, 1 down.
79 trees enountered going 5 right, 1 down.
92 trees enountered going 7 right, 1 down.
33 trees enountered going 1 right, 2 down.

Multiplied together, the answer is: 2421944712
{'fraction_non_alphanumeric': 0.08342813803564657, 'fraction_numerical': 0.02427000379218809, 'mean_word_length': 3.3175122749590833, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '334225', 'license': 'MIT', 'n_tokens_mistral': 824, 'n_tokens_neox': 773, 'n_words': 343, 'path': '2020/day03/main.ipynb', 'repo_name': 'GriceTurrble/advent-of-code-2020-answers', 'size': '2637'}