From 99a7d62c30069a5ffe2210a72c7cf81e76a1f241 Mon Sep 17 00:00:00 2001 From: blenovo Date: Wed, 16 Jul 2025 18:55:48 +0200 Subject: summertime warmup session with 2020 event --- 2020/aoc2020-d03.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 2020/aoc2020-d03.py (limited to '2020/aoc2020-d03.py') 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); -- cgit v1.2.3