0
0
Fork 0

Add advent code for 2020 days 1-4

This commit is contained in:
Oliver-Akins 2020-12-06 20:38:44 -07:00
parent 2c466792a4
commit 948009891a
12 changed files with 256 additions and 0 deletions

30
day_3/part_1.py Normal file
View file

@ -0,0 +1,30 @@
with open("input") as f:
hill = f.read().split("\n")
# Index deltas
slope = [
1, # the change in vertical height of the toboggan
3 # the change in horizontal distance of the toboggan
]
# The starting position of the toboggan
position = [0, 0]
tree_count = 0
while position[0] < len(hill):
# Wrap the pattern as needed
if position[1] >= len(hill[position[0]]):
position[1] -= len(hill[position[0]])
# Check for trees
if hill[position[0]][position[1]] == "#":
tree_count += 1
position[0] += slope[0]
position[1] += slope[1]
print(f"Trees Hit: {tree_count}")