aoc2020/day03.py
2020-12-05 12:16:30 +01:00

44 lines
1.2 KiB
Python
Executable File

#!/usr/bin/env python3
import aoclib
DAY = 3
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
@aoclib.print_execution_time
def part1(test_mode=False):
my_input = aoclib.getInputAsArray(day=3, test=test_mode)
return check_for_trees(3, 1, my_input)
@aoclib.print_execution_time
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
if __name__ == '__main__':
assert part1(test_mode=True) == 7, "Part 1 TEST FAILED"
aoclib.printSolution(DAY, 1, part1())
assert part2(test_mode=True) == 336, "Part 2 TEST FAILED"
aoclib.printSolution(DAY, 2, part2())