36 lines
No EOL
861 B
Python
36 lines
No EOL
861 B
Python
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)]) |