diff options
Diffstat (limited to '2020/aoc2020-d03.py')
| -rw-r--r-- | 2020/aoc2020-d03.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/2020/aoc2020-d03.py b/2020/aoc2020-d03.py new file mode 100644 index 0000000..aa485e0 --- /dev/null +++ b/2020/aoc2020-d03.py @@ -0,0 +1,29 @@ +#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); |
