From 6cdcf92b0cdc1df60d0ec89af10676605cbded1a Mon Sep 17 00:00:00 2001 From: Peter Hudec Date: Mon, 13 Dec 2021 21:12:27 +0100 Subject: [PATCH] added day 03 --- 03/input01.txt | 323 ++++++++++++++++++++++++++++++++++++++++++ 03/input01_sample.txt | 11 ++ 03/solve01.py | 13 ++ 03/solve02.py | 25 ++++ 4 files changed, 372 insertions(+) create mode 100644 03/input01.txt create mode 100644 03/input01_sample.txt create mode 100644 03/solve01.py create mode 100644 03/solve02.py diff --git a/03/input01.txt b/03/input01.txt new file mode 100644 index 0000000..57eaf3a --- /dev/null +++ b/03/input01.txt @@ -0,0 +1,323 @@ +.#..........#......#..#.....#.. +....#.............#.#....#..#.. +.....##...###....#..#.......#.. +.#....#..#......#........#..... +.#.........###.#..........##... +...............##........#..... +#..#..........#..##..#....#.#.. +....#.##....#..#...#.#....#.... +...###...#............#.#...... +#.........#..#...............#. +#.#...........#...............# +..#.#......#..###.#...#..##.... +.....#..#..#..#............#... +......#.......#.....#....##.... +#......#...#.......#.#.#....... +...........##.#.............#.. +.#.........#..#.####........... +..#...........#....##.......... +#...........#.......#..#.#..... +.....##...#.....#..##..#..#.... +#.#..........................#. +##.....#..........#.......##..# +....#..#............#.#.#...... +.......#.......#..#............ +...#.#..........#..#.....#..... +.....#...##..##.....##........# +.#.....#........##............# +..#....#.#...#.....#.##........ +........##.....#......##...##.. +......#..................#..... +..##......##.....##...##....... +......#..#...##......##........ +.#..#..#.#..................... +.#....#.#...#....#.......##...# +.####.#..##...#.#.#....#...#... +.#....#.....#...#..#.........## +...........#.#####.#.#..##..#.. +.#......##...#..###.#.#....#... +...#.....#........#..###...#... +.......#................##.#... +.##...#.#..................#... +..#........#....#..........#..# +..#.........#.................. +...#.#..........#.#..##........ +...#.##..........##...........# +...........#..#........#....... +.#....#.#...........#....#.##.. +.#...#..#............#....#.#.. +...#..#...#.........####.#.#... +..#...#...........###..#...##.# +......##...#.#.#....##....#.... +#..#.#.....##....#.......#...#. +.#.....#.....#..#..##.......... +................#.#.#...##..... +.#.....#............#......#... +...#...#..#.#....######.....#.. +..#..........##......##.....#.. +......#..#.##...#.#............ +....#.......#..#...#..#.#...... +#......##.#..#........#.....#.. +..#.........#..#.........#..... +..#.........##.......#.#.#..##. +...#....##.................#.#. +...#........##.#.......#.##..## +....#.#...#...#....#........... +.........#....##........#...... +...#........#..#.......#...#... +#.......#....#...#...........#. +.......#......#...##........... +.#.#......##.#.......#..#...#.. +.#.....##.#...#......#..#...... +........#.............#.#..#..# +#...........#....#.....#.##.#.# +................#...#........## +#..#.##..#.....#...##.#........ +#.....#.#..##......#.#..#..###. +....#...#.....#................ +......#...#..##...........#.... +......#.........##.#...#......# +#...#.#.....#..#.#..#..#......# +...#.#..#..#.#........###.#.... +..#...#.......#.#.......#...... +...#....#.....#.......#......#. +#...........#....#..#..#....... +..........##......##.........## +##............#..#.#...#..#.#.. +..#.##....##...##..#...#....... +............##.##..###..#..#... +......#....##...##.........#... +......#..#.#......####..#...... +..............#....#..#..##.... +...#.#..#...##.#.......#.#..... +...#.#....#.......#..#..#..##.. +..........#.........#.......... +...#.....#............#.....##. +....#.#......................#. +.........#...#.#...#........... +...#........#..##.....#...#.#.. +......##.....#.#..#...###.#...# +#....#..#.#.....#...#.......... +.#.##.###.........#..##.#....#. +#.........#....#........#...#.. +...........#...............#..# +###....................#....#.. +.................#....#.....#.. +..........#.........#.......#.. +........#..#....#.....##....... +#...##.#...#.#.#............#.. +....#.........##.#.#..#...###.. +.##..............#...#.....##.# +###...#..................#...#. +.....#..#...#..#...#........... +.#.................#...#..#..#. +.#.........###...#.##......###. +.####............#......#..#... +....#........#..#.#....#..##..# +..#....#.#...#.#.....##....#... +..###..#..#....##....#..#..#... +...#.#.....#.#....#.....#...... +.....#..........#.#............ +.......#...........#.#..#..#... +......##........#.....#.......# +..#.#.....##............#..##.. +....#.#........#...........##.. +#......#..##........#.....#.... +#...#...###..............##.... +#..#........#........#.....##.# +......##.####........#..#....#. +...##..#.##.....#...#...#..#... +#..............###.##..##...... +......................#.....#.. +.........#.#.......#...##.#.... +....#......#..........###..#... +#...####.#.................#..# +##.#....#....#.....##..#....#.# +..#.....#..##.........#.#..#.#. +.....#.....#................... +#....##.#.........###....#..... +#........#.#.......#.#......... +.##.#...#.....#...#.......##.## +#..#.............#............. +..........#.........####....... +..##..............#..#.#....... +..#.#.....#........#......##... +#.#.......#.#................#. +.#...#........#....##....#.##.. +.#..#...#...#......#.#......... +......##............#.........# +.#....#.#.#.........#..#..##... +#....#......#.......###........ +.......#........##..#...#..###. +#.##..........#..###..#..#.#... +.#..#....#..........#.#.##..... +#..#...#.#...#..#..#.#...#..... +.........#...#.#............#.. +#..#.............#......##.##.. +...##.......#.................. +....#......#...#.....#......#.. +.....##..#......#....#....#.... +....#...#...#...#.....#........ +.#....#........##....#..#.#...# +#.......#..#......#......#...#. +..............#......#......#.. +#......#..##...#........#....#. +#..#..#..#.....#..#........#... +#...#.....#...#..........#...## +........#.......#...#.....#.#.. +...................##.......#.. +.#......#........#.##..#....#.. +.....#.....#...#..#..#......#.. +........##.#..##.........#....# +.........#.......#............. +............#.###.###..#.#..... +.............#....#...........# +..#.....#.#..##.##........#.... +...#....#....#.........#.....#. +.#............#......#......... +..#.#..........##.##......#.#.. +....#.........................# +..........##................... +#.......#.#..............#...#. +...##..#..##...##.#..#.#.#..... +...########.#..##....#......... +##.#........##.....#........#.. +#.#.....#........#..#....#...#. +..#............#.......###.##.# +#.#............................ +...#.#.#....#..........#..#.... +..###.#.....#.#..#............. +#........#..........#.#..#..... +...........#..#....#.........#. +..#............#.....#.#....... +#.#............#..#.....#.#.#.. +...#...#....................... +.#.#.#...##.............#..#..# +..#.........#..#.....##....##.. +.#...#............#.......#..## +....#..#.#.#...####............ +#.......#....#..##....##....#.. +.....##.#....#.#..#.......#.... +...........#.......#....##.#.## +..........#...#....##...#.#.... +..#.............#.............# +....#..#.....#....#.#..###.#... +.......#.##.#......#...##...#.# +.#..#.#..#.#.......#....###.#.. +#..........##...##.........##.. +##..#......##.#.####.#.....#... +....#.#...#........#..##..#.#.. +.#............................. +.##..#.#...##.....#....#.....#. +..##.........#......#.........# +.#.#........#...#.#.#....##.... +.#.................##.........# +...#...............#....#...... +..#...#..#..........###..#...## +..........#..#..........##..#.. +...#.............#.##.#...#.... +...#...........#............... +......#.........##.#...#...#... +...#.#........#..#.....#..#...# +#.#...#....##...#.....#....#... +#.#.#..#.....#.........#....... +##...........#..####........... +#..........#........###...#..#. +#..#.......#....#......###..... +..#.....#......#.###......##... +...#.##..#............#...#.... +.##........#.....#............. +#....#.##..#...........##.#.#.. +..#.....#.#....#.......#......# +#..#.......#............#...... +#.......##....#...#..#......... +.................#..##......... +..............#..#..#.##....... +#.#.......................#..#. +..#..##...........#....#..#..#. +...#....#.......#.......#....#. +.....#.#..#.#.....#.........#.# +..#.#.........#.....#.......... +...#.#.#.......#.#.......#.#..# +...##...#.#.#.....#.....##....# +##.......#.#.#.#.......#...##.. +....#.#...........#......#..... +.#.....#........####........... +#......#........#.....#..#..#.. +..#..#......#...##.......#....# +#........#..........#.....#.#.. +.#...........#.....#.....#..... +..........#..#...#....#....##.. +.....#.#..........#.....##..#.. +......#.........##............. +..#..#.....##......##........#. +.#.#.#.#..#.#..#.......#....... +#.#...####.#.#....#.#........#. +....#...#.....#......#..##..... +##.........#.........#..#.#..#. +..#.#........#.#........#.##... +#....#......#...#....#......... +.##.............###....###.#... +..##.#.......#...#..#......#... +.....#.##..................#... +.....#.#...#..#................ +........#..#..#...........#.#.# +....#.###.....#..#.#.....##..## +....##.#.........#..##......... +.##........#......#..###..#.##. +.........##...............#.##. +..#...............#.#...#..#.#. +....#....##.....#...#..#.....#. +#...#.....................#.... +.....#.#............#...##.#.#. +...#......#.......#........##.# +.#.#..#.#....#.##.......##....# +.........#...#..##.........#... +.#...#..#....................#. +.......#...#........#.#..#.#.## +.#.............#......#..#.#... +............##.........#....#.# +#.........##..##............... +.#.#....#.#..#..........##..... +..###...#..#.#.......#..#...##. +.....#....#.#............##.#.. +##.....#.#..#..#............... +...##...#......#....#..#..#.... +.............#....#..#..##...## +#.......#............#....##..# +..#.##.....#.......#....#....#. +..........#...#.............### +..#....#.#..................#.. +#.#...#..#...........#......... +....##..#..##..#..........#.... +#...#...#.#....#.##...#.......# +#......##.#...##..#.....#...... +....#.......#.#............#... +#....#...........###........... +#..#...#...#......#.#..#....... +............................... +#........##.............#.#.... +.............#........#....#.## +........##.####.....##..#...... +#.#.#.#.......##....##.....#... +.......#..##..#...#............ +..........#...#....#..#.#.#.##. +...#........##....#...#........ +#..#.##....#....#........#..... +.##...#.....##...#............. +.#...#..#.#.....#.##.....#..... +...........#.............#...#. +.#..#................#...#..#.. +#..........#......##..##....#.. +####..#...........#.#....#..... +..#.#.##..#...##........#....## +.#.......##........#.....#..... +............#................#. +.#...#...#.....#.#....#.##..#.. +..#.............#.#....#.#..... +..............#...........#.... +..............#........#....#.. +..........##........#..#...#... +...#.#....#.#....#..#.....#...# +..#......#...........#..#..#.#. +.....##.....#.####....#........ \ No newline at end of file diff --git a/03/input01_sample.txt b/03/input01_sample.txt new file mode 100644 index 0000000..8f551de --- /dev/null +++ b/03/input01_sample.txt @@ -0,0 +1,11 @@ +..##....... +#...#...#.. +.#....#..#. +..#.#...#.# +.#...##..#. +..#.##..... +.#.#.#....# +.#........# +#.##...#... +#...##....# +.#..#...#.# \ No newline at end of file diff --git a/03/solve01.py b/03/solve01.py new file mode 100644 index 0000000..963daca --- /dev/null +++ b/03/solve01.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python + +stepX = 3 +posX = 0 +trees = 0 +with open("input01.txt","r") as f: + for line in f: + line = line.strip() + if line[posX] == '#': + trees +=1 + posX = (posX + stepX) % (len(line)) + +print(trees) \ No newline at end of file diff --git a/03/solve02.py b/03/solve02.py new file mode 100644 index 0000000..75c2fbb --- /dev/null +++ b/03/solve02.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python + +def count_trees(area, stepX, stepY): + trees = 0 + posX = 0 + for i in range(0, len(area), stepY): + line = area[i] + if line[posX] == '#': + trees +=1 + posX = (posX + stepX) % (len(line)) + return trees + +area = [] +with open("input01 .txt","r") as f: + for line in f: + area.append(line.strip()) + +result = 1 +result *= count_trees(area, 1,1) +result *= count_trees(area, 3,1) +result *= count_trees(area, 5,1) +result *= count_trees(area, 7,1) +result *= count_trees(area, 1,2) + +print(result) \ No newline at end of file