Cleared days 1, 2, 3 and 4

This commit is contained in:
cato447
2021-08-16 17:21:54 +02:00
parent 96c317627b
commit abb014cf52
12 changed files with 2799 additions and 0 deletions

39
Scripts/Day 3.py Normal file
View File

@@ -0,0 +1,39 @@
import numpy as np
def first():
with open("/Users/cato447/Code/Cato447/AdventOfCode_2020/Scripts/res/day3.txt") as f:
lines = [line.replace("\n", "").split() for line in f.readlines()]
column = 0
trees = 0
for line in lines:
if line[0][column] == '#':
trees += 1
if column < len(line[0])-3:
column += 3
else:
column += 3
column -= len(line[0])
return trees
def second():
with open("/Users/cato447/Code/Cato447/AdventOfCode_2020/Scripts/res/day3.txt") as f:
lines = [line.replace("\n", "").split() for line in f.readlines()]
stepsX = [1, 3, 5, 7, 1]
stepsY = [1, 1, 1, 1, 2]
countTrees = []
for stepX, stepY in zip(stepsX, stepsY):
column = 0
trees = 0
for index in range(0,len(lines),stepY):
if lines[index][0][column] == '#':
trees += 1
column += stepX
if column > len(lines[index][0])-3:
column -= len(lines[index][0])
countTrees.append(trees)
return np.prod(countTrees)
print(f"First solution: {first()}")
print(f"Second solution: {second()}")