2020 AoC, Days 1-4
This commit is contained in:
commit
5cef034755
9 changed files with 2782 additions and 0 deletions
36
2020/Day 3/Solution.py
Normal file
36
2020/Day 3/Solution.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
input_file = "/tmp/aocinput"
|
||||
|
||||
map_table = []
|
||||
|
||||
with open(input_file) as slope_map:
|
||||
line = slope_map.readline()
|
||||
while line and line != "\n":
|
||||
map_table.append(line)
|
||||
line = slope_map.readline()
|
||||
|
||||
def check_for_trees(direction=(3,1)):
|
||||
x_pos = 0
|
||||
y_pos = 0
|
||||
|
||||
width = len(map_table[0])
|
||||
height = len(map_table)
|
||||
|
||||
tree_count = 0
|
||||
|
||||
while y_pos < height-1:
|
||||
x_pos,y_pos = ((x_pos+direction[0])%(width-1),y_pos+direction[1])
|
||||
if map_table[y_pos][x_pos] == "#":
|
||||
tree_count += 1
|
||||
|
||||
print(f"We came close to {tree_count} trees by going {direction}.")
|
||||
|
||||
return tree_count
|
||||
|
||||
def check_multiple_directions(directions):
|
||||
result = 1
|
||||
for direction in directions:
|
||||
result *= check_for_trees(direction)
|
||||
|
||||
print(f"Result is {result}.")
|
||||
|
||||
check_multiple_directions([(1,1),(3,1),(5,1),(7,1),(1,2)])
|
Loading…
Add table
Add a link
Reference in a new issue