Some cleanup, added a few comments all around

This commit is contained in:
Teo-CD 2020-12-05 00:04:09 +01:00
parent ad04dffb69
commit f44d5b9e66
6 changed files with 51 additions and 17 deletions

View file

@ -1,4 +1,4 @@
input_file = "/tmp/aocinput"
input_file = "input.txt"
map_table = []
@ -8,7 +8,8 @@ with open(input_file) as slope_map:
map_table.append(line)
line = slope_map.readline()
def check_for_trees(direction=(3,1)):
def check_for_trees(direction=(3, 1)):
x_pos = 0
y_pos = 0
@ -17,8 +18,10 @@ def check_for_trees(direction=(3,1)):
tree_count = 0
# Might pose an issue for y speed different than a divisor of the number of lines ?
while y_pos < height-1:
x_pos,y_pos = ((x_pos+direction[0])%(width-1),y_pos+direction[1])
# x wraps around as the map is repeated on the right indefinitely
x_pos, y_pos = ((x_pos+direction[0]) % (width-1), y_pos+direction[1])
if map_table[y_pos][x_pos] == "#":
tree_count += 1
@ -26,6 +29,7 @@ def check_for_trees(direction=(3,1)):
return tree_count
def check_multiple_directions(directions):
result = 1
for direction in directions:
@ -33,4 +37,5 @@ def check_multiple_directions(directions):
print(f"Result is {result}.")
check_multiple_directions([(1,1),(3,1),(5,1),(7,1),(1,2)])
check_multiple_directions([(1, 1), (3, 1), (5, 1), (7, 1), (1, 2)])