#advent of code 2020 #day 03 grid = dict(); limY = 0; limX = 0; PuzzleInput = open("03.in","r"); for y,line in enumerate(PuzzleInput): for x, c in enumerate(line): grid[(x,y)] = c; limX = max(limX,x); limY = max(limY,y); PuzzleInput.close(); slopes = [(1,1),(3,1),(5,1),(7,1),(1,2)]; p1 = 0; p2 = 1; for slope in slopes: stepX, stepY = slope; MyPosX = 0; MyPosY = 0; trees = 0; while MyPosY < limY : MyPosX += stepX; MyPosY += stepY; if grid[(MyPosX%limX),MyPosY] == "#": trees +=1; p2 *= trees; if slope == (3,1): p1 += trees; print("part 1 = ",p1); print("part 2 = ",p2);