diff options
| author | blenovo <bk@gmail.com> | 2025-07-16 18:55:48 +0200 |
|---|---|---|
| committer | blenovo <bk@gmail.com> | 2025-07-16 18:55:48 +0200 |
| commit | 99a7d62c30069a5ffe2210a72c7cf81e76a1f241 (patch) | |
| tree | 71c5c529b7f2fda9b5b5897a56a4ef3199400709 /2020/aoc2020-d03.py | |
| parent | 15662865f0886209d871a7225bfc62cffd2e0783 (diff) | |
summertime warmup session with 2020 event
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); |
