aoc2020/day03.py

36 lines
943 B
Python
Executable File

import aoclib
DAY = 3
TEST_SOLUTION_PART1 = 7
TEST_SOLUTION_PART2 = 336
def check_for_trees(right_step, down_step, treelines):
x = 0
y = 0
tree_count = 0
maxX = len(treelines[0])
while y < len(treelines):
if treelines[y][x] == '#':
tree_count = tree_count + 1
y = y + down_step
x = (x + right_step) % maxX
return tree_count
def part1(test_mode=False):
my_input = aoclib.getInputAsArray(day=3, test=test_mode)
return check_for_trees(3, 1, my_input)
def part2(test_mode=False):
my_input = aoclib.getInputAsArray(day=3, test=test_mode)
tree_count1 = check_for_trees(1, 1, my_input)
tree_count2 = check_for_trees(3, 1, my_input)
tree_count3 = check_for_trees(5, 1, my_input)
tree_count4 = check_for_trees(7, 1, my_input)
tree_count5 = check_for_trees(1, 2, my_input)
return tree_count1 * tree_count2 * tree_count3 * tree_count4 * tree_count5