49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
def tree_counter(horizontal_shift, vertical_shift, input_list):
|
|
tree_count = 0
|
|
row_count = 0
|
|
for i in range(0, len(input_list), vertical_shift):
|
|
horizontal = row_count * horizontal_shift
|
|
vertical = i
|
|
|
|
reference = horizontal % len(input_list[i])
|
|
if input_list[i][reference] == "#":
|
|
tree_count += 1
|
|
|
|
temp_input = input_list[i]
|
|
if temp_input[reference] == "#":
|
|
temp_input = temp_input[:reference] + "X" + temp_input[reference + 1:]
|
|
if temp_input[reference] == ".":
|
|
temp_input = temp_input[:reference] + "O" + temp_input[reference + 1:]
|
|
|
|
row_count += 1
|
|
print(f'''"Row {f"""{vertical}/{len(input_list) - 1}""":8} {temp_input:35} {i:5} {horizontal:5} {vertical:5} {tree_count:4}''')
|
|
return tree_count
|
|
|
|
# with open('./2020/03.test') as input:
|
|
with open('./2020/03.input') as input:
|
|
input_list = input.read().split('\n')
|
|
|
|
tree_count = 0
|
|
for i in range(len(input_list)):
|
|
horizontal = i * 3
|
|
vertical = i
|
|
|
|
reference = horizontal % len(input_list[i])
|
|
if input_list[i][reference] == "#":
|
|
tree_count += 1
|
|
print(tree_count)
|
|
|
|
slope_list = []
|
|
slope_list.append(tree_counter(1, 1, input_list))
|
|
slope_list.append(tree_counter(3, 1, input_list))
|
|
slope_list.append(tree_counter(5, 1, input_list))
|
|
slope_list.append(tree_counter(7, 1, input_list))
|
|
slope_list.append(tree_counter(1, 2, input_list))
|
|
|
|
total = slope_list[0]
|
|
|
|
for i in range(1, len(slope_list)):
|
|
total *= slope_list[i]
|
|
|
|
print(slope_list)
|
|
print(total) |