Some cleanup, added a few comments all around
This commit is contained in:
parent
5cef034755
commit
5e94b4e474
6 changed files with 51 additions and 17 deletions
|
@ -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)])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue