/ ---
/ jupyter:
/   jupytext:
/     text_representation:
/       extension: .q
/       format_name: light
/       format_version: '1.5'
/       jupytext_version: 1.14.4
/ ---

/ + [markdown] cell_id="00000-62fe81c4-30d4-42c0-8d57-0d7a519c8049" deepnote_cell_type="markdown" tags=[]
/ ## Day 3
/
/ With the toboggan login problems resolved, you set off toward the airport. While travel by toboggan might be easy, it's certainly not safe: 
/ there's very minimal steering and the area is covered in trees. You'll need to see which angles will take you near the fewest trees.
/
/ Due to the local geology, trees in this area only grow on exact integer coordinates in a grid. You make a map (your puzzle input) of the open 
/ squares (.) and trees (#) you can see. For example:
/
/ ```
/ ..##.......
/ #...#...#..
/ .#....#..#.
/ ..#.#...#.#
/ .#...##..#.
/ ..#.##.....
/ .#.#.#....#
/ .#........#
/ #.##...#...
/ #...##....#
/ .#..#...#.#
/ ```
/ These aren't the only trees, though; due to something you read about once involving arboreal genetics and biome stability, 
/ the same pattern repeats to the right many times:
/
/ ```
/ ..##.........##.........##.........##.........##.........##.......  --->
/ #...#...#..#...#...#..#...#...#..#...#...#..#...#...#..#...#...#..
/ .#....#..#..#....#..#..#....#..#..#....#..#..#....#..#..#....#..#.
/ ..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#
/ .#...##..#..#...##..#..#...##..#..#...##..#..#...##..#..#...##..#.
/ ..#.##.......#.##.......#.##.......#.##.......#.##.......#.##.....  --->
/ .#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#
/ .#........#.#........#.#........#.#........#.#........#.#........#
/ #.##...#...#.##...#...#.##...#...#.##...#...#.##...#...#.##...#...
/ #...##....##...##....##...##....##...##....##...##....##...##....#
/ .#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#  --->
/ ```
/
/ You start on the open square (.) in the top-left corner and need to reach the bottom (below the bottom-most row on your map).
/
/ The toboggan can only follow a few specific slopes (you opted for a cheaper model that prefers rational numbers); start by counting 
/ all the trees you would encounter for the slope right 3, down 1:
/
/ From your starting position at the top-left, check the position that is right 3 and down 1. Then, check the position that is right 3 
/ and down 1 from there, and so on until you go past the bottom of the map.
/
/ The locations you'd check in the above example are marked here with O where there was an open square and X where there was a tree:
/
/ ```
/ ..##.........##.........##.........##.........##.........##.......  --->
/ #..O#...#..#...#...#..#...#...#..#...#...#..#...#...#..#...#...#..
/ .#....X..#..#....#..#..#....#..#..#....#..#..#....#..#..#....#..#.
/ ..#.#...#O#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#
/ .#...##..#..X...##..#..#...##..#..#...##..#..#...##..#..#...##..#.
/ ..#.##.......#.X#.......#.##.......#.##.......#.##.......#.##.....  --->
/ .#.#.#....#.#.#.#.O..#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#
/ .#........#.#........X.#........#.#........#.#........#.#........#
/ #.##...#...#.##...#...#.X#...#...#.##...#...#.##...#...#.##...#...
/ #...##....##...##....##...#X....##...##....##...##....##...##....#
/ .#..#...#.#.#..#...#.#.#..#...X.#.#..#...#.#.#..#...#.#.#..#...#.#  --->
/ ```
/
/ In this example, traversing the map using this slope would cause you to 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?

/ + cell_id="00000-a28097c3-2007-436c-ab94-9c0784b236f3" deepnote_cell_type="code" execution_millis=3 execution_start=1607432870170 output_cleared=false source_hash="ee86501a" tags=[]
forest = list(map(str, open('../data/day03_input.txt', 'r').read().split('\n')))

/ + cell_id="00010-43e78a62-994e-4482-968b-907c68f5eaf2" deepnote_cell_type="code" execution_millis=0 execution_start=1607432870699 output_cleared=false source_hash="e43dcf69" tags=[]
def find_trees(forest, right, down):
    trees, y = 0, 0
    for index, row in enumerate(forest):
        if index % down == 0:
            if row[y] == "#":
                trees+=1
            y = (y + right) % 31
    return trees

/ + cell_id="00003-117e6e97-9c24-452f-a777-77630d4be336" deepnote_cell_type="code" execution_millis=2 execution_start=1607432871219 output_cleared=false source_hash="42678ecd" tags=[]
# Answer to part one:
find_trees(forest,3,1)

/ + [markdown] cell_id="00004-4e8281a3-00ca-4acc-8c23-94c7e34da50d" deepnote_cell_type="markdown" tags=[]
/ ## 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?

/ + cell_id="00012-db60c96f-4daf-45ee-94f6-3d1fa65fc01d" deepnote_cell_type="code" execution_millis=2 execution_start=1607432874535 output_cleared=false source_hash="dd015bc7" tags=[]
# What do you get if you multiply together the number of trees encountered on each of the listed slopes? (Answer to part 2)
print(find_trees(forest,1,1)*find_trees(forest,3,1)*find_trees(forest,5,1)*find_trees(forest,7,1)*find_trees(forest,1,2))

StarcoderdataJupyterScriptsDedupFiltered