From 95e56b933343d657507215ff8b07061e2d730a61 Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Thu, 3 Dec 2020 07:05:29 +0100 Subject: [PATCH] day3 --- aoclib/inputs.py | 2 +- day03.py | 47 +++++++ inputs/3 | 323 +++++++++++++++++++++++++++++++++++++++++++++++ inputs/3_test | 11 ++ 4 files changed, 382 insertions(+), 1 deletion(-) create mode 100644 day03.py create mode 100644 inputs/3 create mode 100644 inputs/3_test diff --git a/aoclib/inputs.py b/aoclib/inputs.py index b28097e..2133778 100644 --- a/aoclib/inputs.py +++ b/aoclib/inputs.py @@ -15,7 +15,7 @@ def getInputLineAsArray(day, return_type=None, test=False): file = os.path.join(INPUTS_PATH, str(day)) with open(file, "r") as f: - input_array = f.readlines() + input_array = f.read().splitlines() if return_type: return [return_type(i) for i in input_array] diff --git a/day03.py b/day03.py new file mode 100644 index 0000000..b06d228 --- /dev/null +++ b/day03.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +import aoclib + +DAY = 3 + + +def check_for_trees(right_step, down_step, treelines): + x = 0 + y = 0 + tree_count = 0 + for treeline in treelines: + if y % down_step != 0: + y = y + 1 + continue + + while len(treeline) < x + 1: + treeline = treeline + treeline + + if treeline[x] == '#': + tree_count = tree_count + 1 + + x = x + right_step + y = y + 1 + + return tree_count + + +def part1(test_mode=False): + my_input = aoclib.getInputLineAsArray(day=3, test=test_mode) + return check_for_trees(3, 1, my_input) + + +def part2(test_mode=False): + my_input = aoclib.getInputLineAsArray(day=3, test=test_mode) + tree_count1 = check_for_trees(1, 1, my_input) + tree_count2 = check_for_trees(3, 1, my_input) + tree_count3 = check_for_trees(5, 1, my_input) + tree_count4 = check_for_trees(7, 1, my_input) + tree_count5 = check_for_trees(1, 2, my_input) + return tree_count1 * tree_count2 * tree_count3 * tree_count4 * tree_count5 + + +if __name__ == '__main__': + assert part1(test_mode=True) == 7, "Part 1 TEST FAILED" + aoclib.printSolution(DAY, 1, part1()) + assert part2(test_mode=True) == 336, "Part 2 TEST FAILED" + aoclib.printSolution(DAY, 2, part2()) diff --git a/inputs/3 b/inputs/3 new file mode 100644 index 0000000..e4e0663 --- /dev/null +++ b/inputs/3 @@ -0,0 +1,323 @@ +........#.............#........ +...#....#...#....#............. +.#..#...#............#.....#..# +..#......#..##............###.. +..........#......#..#..#....... +.#..#.......#.........#.#...... +.........#..#....##..#.##....#. +..#....##...#.................. +##..........#.##...#....##..#.. +...#....#...#..............#... +...........................#..# +..##.##.#..................#... +...#.##..#............#........ +........#.......#...#.....##.#. +.##..........#......#.......#.. +...#..........#...#..#.......#. +......#...#...#.##.......#.#... +........#...#...#...##......... +#..............#.#....#.......# +..#..#..#.#....#............... +.....#........#...#..........#. +##......#...#..#.##.......#.... +..#.#.....#.#.............#.#.# +#..#..##......##...#........... +..#......#........#.....#...... +.....#.......#....#.#...#...... +...#........#...........#...#.. +.......#.#...........###....#.. +...#...........##....##........ +#....#..####....#.....#..#....# +..........#...........#........ +...#.......#....#.#.........#.. +....#...#.......#..###......... +......#......#..#......#..#.... +...#.....#............#..#..... +...#.#.#.#..#.......#.....#.... +#....##...#.........#...##..... +#..#.......#..#..#..#...##..... +#.......#............#.....#... +.#........##....##...#........# +.....#...#..................... +.......#........#.............. +.....#............#.#.#...#.#.. +.....##..#.............#....... +..#.##..#........#..#...#...... +.........#.#....#...........#.. +.#.....#..#....#.....#...#..... +....#.#................#....... +...............##......#...#... +.##...#...#.......##.#....#.... +............#........#.......#. +......##.#.#................... +.#.#..............#.......#.... +#.....#...#.......#..#...#..... +.............#....#..#......#.. +........#...##................# +.......#...#..#..##............ +..#..#...##...#..#.#.....#...#. +.#.#...#.........#.#........... +...###....#.......#...#........ +........#......##.#...#..##..#. +.....................#.#....... +.............#...........#...#. +#..#..#.....#.#...#............ +...#....#.....#...........#.... +..##.....##...#......#..##..... +#.....#.....###.#.....#....##.. +.#...........###............... +..................#..##.#...#.. +................#....##.#...... +.#.#.#...#....#.........#..#.#. +#.......#........##............ +.......##.#....#.#............# +..........#..##.#....#......... +........##..#....#............. +.........#....#...........##... +#.........#.#..#..#..........#. +.....#........#......#......... +....#.#.#...............#...... +.#..#..##...#.##..........#.... +..#....................#.#..... +.........#....#...........#.#.# +........#....##.##............. +..#.....#.......#..#......#.... +#..........#.#.....#.#....#.... +........##.#.....#..#.....#.#.. +...................#...#....#.# +............#..#....#...#...#.. +..............#.#.........#.... +...#..#..#.#..##..##........... +.#...........................#. +.#.......#...........#....#.#.# +......#..#...#........#...##... +.........#......#.#.......#...# +...#..##................#...... +.............#.#..##....#.#.... +...............#..#......#..... +.#......#.#.#....#........#.... +........#..#.##..#..#.........# +...#....#.#...#..#.......#..#.. +..#...##.........#..#...#...... +...#...........#.............#. +....#.....................#.... +.....#..#...............#.#...# +....#..........#........#...... +..#....#........##..##......... +...#....#..#.#.......#...#..... +..#........#....#...##....#.#.. +.#...#........##.....#....###.. +#....#....##......#........#... +.........#..#.#..........#....# +....#...#.....#.......##....... +..............#..........#.##.. +#...#..#..............#......#. +.................#......##....# +..#..##..#.......#..#.#......#. +.............#........#.....#.# +.#.##............#..#.......... +..#...#...........#..##........ +.#....#...#....#.......#....... +...#.#..#..#..#....#.....#..#.. +....#..##..............#...#... +#..........###......###........ +.##.##......#..#............#.. +.#...........#.#.....#...#..... +#.#..#...#............#........ +.........#...#...#..........##. +.......###..#..........#....... +...........###.....#........#.. +.#.............#.....#......#.. +...#.....#....#.#.........##... +....##..##...#.......##........ +......#....##.........#......#. +..........#.....##..#.....#..#. +..........####...#..#.........# +.##....#..#.#...#.......#...... +...#.#.##.#.#...#....#.#.#..... +.........#...##........##.....# +..#........#..........##...##.# +##...##..........#.#........... +..............#......#......... +........#.....#.#.......#...... +.#...#.....#....#.#..#......... +.....#....................##... +....#..................#.#...## +.....#............#..##........ +#..........#....#.#.......##.#. +....#..#.....................#. +#..#....##.....#............... +..#...#..#..##....#.#.......... +.......#......#.#.......#.....# +...#.#.......#...#.##.......... +....#..........#....#.#.#...... +.......#..#..........#..##..... +#......#......#...#......#...#. +###..#....##......##........#.. +.#..........#.....#.......#.#.. +.......#.....#.....#.#......... +..#...#....#................... +..............#.##............. +.#...#.......#.##...#.#.......# +.......#......................# +....#.#...#.#........#......... +.#......#....#...#............. +#.......#...###.....#.#.#..#... +#....##.#...............##..... +..#.......#..................#. +.....####...............#...... +.##......#......#.#.......##.#. +#......##..###....#....#......# +.##.......##.##...#.##......... +......##............#.......#.. +......#..#.....##.#............ +.#..........#.....##........... +#.........#......#......##.#... +.........#.......#..#......#.#. +.........#.......#...........#. +.#..##.#..................##... +.............#.............#... +.....##........#......##...##.. +..#..#.#.....#..#....#......... +.....#....#.....#.....#........ +#......##.....#....#....#...... +#.................#..#.#......# +.......#..#......#....#.#...#.# +....#.........#..#..........#.# +##......#............#...#...#. +....##......#...#.....#....##.. +.#...##.........#.............. +......#.....................#.. +..#..........###....#.......... +#....#...#..#.............#.... +#........#.#......#....#....... +.#...#.......#..#...#.#...#..#. +................##.#.....#..... +###.......#...#................ +...#.......#...#.#.....#....... +..#.........#.....#.#.......#.. +......#.......................# +#.....#.#..#....#.......#...... +...#....#..#....####........... +.............#.....#...##...... +.......#.........#...#..#...... +.##..#.........#....#.#........ +....##...#.#...........#....#.. +.........................##.... +..###.......##....#.#.........# +.#....#.#.#...........##....#.. +......#...#..#..#..#..#.......# +..#....#.#.......#..#..#..#...# +.....##...#.##....#.#...#...... +.........#..#....#..#.......... +.##..##.........#.#.....#...... +..........#...##...#.#...#..... +#.##..#..#.............#....... +...#...........#.......#......# +.......#....#....#...##.......# +..#.##........###..#......#.... +...#...........###......#..#..# +.#.........#.#.........#.#..... +##.......##.##.##......##...... +............#...#..........#... +....................#.......... +...#..#...........#...#...#.... +.................#...#......### +...#................#.#.##..... +...............#........#...... +#.............##......#.#..#... +..#.#.....#..#.##.....##...#... +......#.........#......#....... +#.......#......#....#........#. +.#..##.....#.........#......... +....##.##.#...#.........##.#... +...............#..#..#..##..... +.#..#...............###........ +.##............##.............. +...............#...##...#...#.# +..#.#......#.#..#.............# +#.#..#..##.........#.#.#...#... +....##.#....................##. +.........#..#.....#.....#..#..# +....#......#......#.##....#.... +........###..#.............#..# +##................#.........#.. +#.....#.......#....#........... +..#.......#..#........#....#... +..#.#.##..#.#...##........#.##. +..#..........#............#.... +..........#...............##... +..........###........#.#....... +.....###..#.............#...... +##.............#...#.....#..... +.....#......#....#........#.#.. +............#..#..............# +.................#...........## +#........#.........###.....#... +..#.#..............##......#.#. +.#...........#.........#..##..# +............................... +.#.....#..#....#....#......#... +.#...#......#.#..#....#.......# +......#.##.......#......#...... +......#..###..#................ +#..#.....#........##...#....... +......##.........##....#...##.. +.#..........#.................# +#..#.......#...............#... +.........#..###....#.#.##.#.... +..#...#.##..##...............## +.........#..................... +.#....##...#......#....#....... +............#..........#..#.... +...#......##....#....#........# +.#...................#......... +#.#........###....#..........#. +.........#....#....#........##. +.#....#..#.........#..#........ +...............#..#...#..#...## +.........#....##....#......#... +.#............................. +...#........#...#.#...#.#..#... +.....#..##...#.#............... +#.....#....#.........#......... +#...#...........##.........#... +..##........#.#...#...#......#. +...........#.....#...#.#....... +......###....#.....#........... +......##...#..........#....#.#. +.......##..##..........#....... +....#............#..#....##.... +..##...................#.#..... +...#.#..#.#.................... +.#..##..#............##.###..#. +#.#...#....#.#..........#.#.... +........#....#.....#........... +..##....#...#.......#.......... +...........##.##....#.......... +.....#............#............ +.......#.............#....#.... +.................#......#...... +......##.......#....#..##...#.. +.#..#....#..................... +...#.#.#...#......##........... +##........##.#....#....#....... +.......#.....#..#..#...#.##.... +#..........#....#.#..#..#..#... +...##..............#........... +.........#.....#.#....#.......# +.........#....##..#..##..#..... +.....#......................#.. +...###...#..#......#........... +....#.....................#.... +............................... +..#.....###.......#..#....#.... +#..........#.................#. +......#.......###.......#..##.. +.............#.##.............. +......#..#.#..#...........#.... +...#....##.#...#..#.#...#....#. +..................#...#....#.## +......#.#....#................. +......#.#.....#.....#..##...... +#..##...........#..#.....#.##.. diff --git a/inputs/3_test b/inputs/3_test new file mode 100644 index 0000000..7e88cdc --- /dev/null +++ b/inputs/3_test @@ -0,0 +1,11 @@ +..##....... +#...#...#.. +.#....#..#. +..#.#...#.# +.#...##..#. +..#.##..... +.#.#.#....# +.#........# +#.##...#... +#...##....# +.#..#...#.#