DEV Community

Discussion on: Advent of Code 2020 Solution Megathread - Day 3: Toboggan Trajectory

Collapse
 
justsax profile image
JustSaX • Edited

My solution in Python below for part 1. The hardest part for my was to figure out that the starting point is one further to the right then I expected...

file = open('d3-input.txt')
input_file = file.readlines()
input_file = [line.replace('\n','') for line in input_file]

right_counter = 3
count_trees = 0
for index, line in enumerate(input_file):
    if index > 0:
        if list(line)[right_counter] == '#':
            count_trees+=1
        right_counter+=3
        if right_counter >= len(line):
            right_counter = right_counter-len(line)
print(count_trees)

Enter fullscreen mode Exit fullscreen mode