## DEV Community is a community of 607,586 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

loading...

# Advent of Code 2020: Python Solution Day 3 Viper Updated on ・1 min read

This is Day 3 of the challenge and it is more challenging.
The challenge can be found here.
Also there is a Jupyter Notebook along with my input on this GitHub Repository.
My solution on Python is given below.

``````# 1
with open("day3.txt", 'r') as f:
lines=f.readlines()

curr_x = 0

slope_x = 3
slope_y=1

trees = 0
for curr_y, each_line in enumerate(lines):
if each_line[curr_x] == "#":
trees+=1
curr_x = (curr_x + slope_x) % len(each_line[:-1])
print(f"Solution 1:{trees}")

#2
slopes = [(1,1), (3,1), (5,1), (7,1), (1,2)]
mult_trees=1
for slope in slopes:
print("Slope: ", slope)
slope_x, slope_y=slope
trees = 0
curr_x = 0
for curr_y, each_line in enumerate(lines):
if curr_y%slope_y == 0:

if each_line[curr_x] == "#":
trees+=1
curr_x = (curr_x + slope_x) % len(each_line[:-1])
print("Trees on this slope: ", trees)
mult_trees*=trees
print("Solution 2: ", mult_trees)

``````

I write blogs about Computer Vision projects on my GitHub page q-viper.github.io and if you got some time please share yours too.

## Discussion (1) 