From 34f71edd66e22b7d1e1b262d92d80e1bf335aa57 Mon Sep 17 00:00:00 2001 From: Cody Hiar Date: Mon, 25 Jan 2021 12:34:50 -0700 Subject: Initial commit --- day3/day3.py | 35 +++++++ day3/input | 323 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 358 insertions(+) create mode 100644 day3/day3.py create mode 100644 day3/input (limited to 'day3') diff --git a/day3/day3.py b/day3/day3.py new file mode 100644 index 0000000..716dc5e --- /dev/null +++ b/day3/day3.py @@ -0,0 +1,35 @@ +from functools import reduce +from itertools import islice + + +def nth(iterable, n): + return next(islice(iter(iterable), n, n + 1)) + + +def mult(iterable): + return reduce(lambda x, y: x * y, iterable) + + +def count_trees(data, right, down): + return [nth(row, right * idx % len(row)) for idx, row in enumerate(data[::down])].count("#") + + +data = list(map(str.strip, open("input"))) + + +# Part 1 +down = 1 +right = 3 +print(count_trees(data, right, down)) + + +# Part 2 +slopes = [ + # R, D + [1, 1], + [3, 1], + [5, 1], + [7, 1], + [1, 2], +] +print(mult([count_trees(data, right, down) for right, down in slopes])) diff --git a/day3/input b/day3/input new file mode 100644 index 0000000..8285f03 --- /dev/null +++ b/day3/input @@ -0,0 +1,323 @@ +.....#....#...#.#..........#... +...#.................#......... +......#...#.#.#.....#..#.....#. +.........#.#.............##.... +#..####..#..#.##.....#......... +...#........#..##...........#.. +..##.#.#..#....#..#......#.#... +.......#.##....#.....###....#.# +.#..#...#......#..#....##.#.... +...#...............#.#.....#... +..#............#..#.........#.# +#.#.#.............##.#......#.. +#...#..............##...#.#.... +...#....#................#.#..# +..#.#..#.#.#..#.....#.........# +#.............#..#..........#.. +.#...#.#........###.#....#...#. +#......#....#.#..#.##..#....... +.##......###.#......#..##...#.. +#..#....#........#......#.#.... +.#..................#.....#.### +.#......#.#.#.....#...#.#...... +....#.............#.#.......... +....#..#.#........#..###....... +.....#....#...#........#....... +...........#.###....##.......#. +....#...........#.#..#...#..... +...........#.....#.#........... +.....#........#.....#.#..#....# +#.#......#.......#.......#..... +..........#.............#.#.#.. +#...#..........#....#....#..... +.#.#......#..##...#.....#...##. +.#....#...#.#.......#.#........ +....#....##.##...#............. +#...#....#..#.........#........ +...#.....#.#...#.......#..#.... +#.......#...#....##........#..# +####........#........#....#.#.. +............##..........#...... +.......#.....#.#.#.##..#...#... +..........#....#...##.........# +..##..####.......##......#.##.. +.....#.#......##...#..#...#.... +....#.#.#.........#........#... +...........###...#.........##.. +.......#.#....#......#.##...##. +.................#...##.#...##. +.......#.......#..#.#.......... +.#....#..#....#........#....... +...............#.##..#...##..#. +.###.#....#......#...#.#.....#. +.#.....##.......#.......#...... +....#..#.....#.....#........... +.......#....#.................# +.......#.##...#...#......#..... +.#.....#...####.............#.. +......#.........#..........#... +.........#....#....#........### +....#.........#......##.....#.. +....#........##...##.....##...# +.#..#....#..........#...#.###.# +#..#......#...#........#....... +...#.........................#. +.............#........#........ +.......#.#.#.....##.....#..#... +..##..##.........#............. +.#...#..#......#...##..##..###. +.....#....#...#...##.##........ +.#.#..#...........#..#..#...... +##..#...#..#...##..#....#...... +...#...#...#.........#....###.. +...##..#....#.#.#.......#...#.. +..#.#.....#..#....#..##.......# +.....#.#.....#......#....#.#... +.......##....#.....#...#.....#. +..##..#.................#.#.... +..............##....##.#..##... +.#..#.....#....#.#.#........... +......#.#.#..#..#...#.....#..## +..#.........#.#.......###...##. +#.....#...........#.....#.##.#. +#..........#....#....#..#....#. +.#.....#...#.......###......#.. +....##..##......#....#....#.... +.......#.#.............#....#.# +.#..#.##.##.##....#.#.....##.## +....#..##.#..#.............##.. +....#...........#...#....#..#.. +...........#..#....#....##.#.## +......#....#....#.....#......#. +.##.##....#.....#.#......#...#. +.....##.......#.#.#........##.. +#..........##..#....#..#.#....# +...#........................... +...#..#...#..#.#.#.#.......#.#. +.....#.........#..###.......... +...#.#......##....#......#..### +#..............#....#.......#.. +.........##......###..###...... +..#......##...........#.##..... +#.#..#......#...##............. +......#.#.............#....#..# +#.....##..#.#.................# +..##....#.....#....#.....###... +.#.#.##.....#.................. +.#......#.#.#.....#..#....#.... +..#.#.....##.#...#..#.#.##..... +..#.#..#......##.#.#..........# +.......##.....#..#...#....##.#. +...#.....#..........#.......... +......................##......# +...###.........##.........#.... +....#..................#.....#. +.##..#.............#........##. +....#....#...###..........#.... +.....#.#..........###.......... +..#......##......#.#.##.#..#... +##...........#.#..#.....#..#... +.........#......#..........#.#. +...#.##.#..#..###..#........... +....##.#.##...........#.....##. +....#...................###.... +#.......#......#......#.....#.. +#..........##.................. +...#..#.#....#..#.........##.#. +......#...##.#...............#. +.........#....#.#...#..#..#.... +...#......###..#......#.....#.# +#..###.#.............#......... +......#...........#............ +..#..#.##.....#......#.#..#...# +.........#..............#...... +........#.....#..#...#.....#..# +.....................#........# +.##.......##...#.###.........#. +.#...#.......#.#....##....#.... +........#......#...........#.#. +....#......##...#.....#...#...# +..#.........#.#...............# +....#.....#......#............. +.............##.....#....#..... +........#......#.#.....#....#.. +#.........#...#......#....#...# +.#........###...#.#.#...#....#. +.###...........#..#............ +....##.........#..#...##.#..### +.####..#.#...............##.#.. +#.....#...#....#.......##....#. +..#.....##...##.#...#..#....... +..#.###.......#.....#.......#.. +...........#.......#....##....# +..#...#....##........###......# +...#..#..............#...#..... +##.#.............#....##.#..##. +##.#..#..............#.#....... +.......#....#....##............ +.##..##.#..........#.#...#.#... +.........##.......##...#...#... +............#...##....#...#.... +........#...#..#...#.##......#. +..#...#.#.........#.#....#..... +..#...#.#..#.......#.#......... +.......#.....#...#.#..###....#. +.#......#.#....#.#.####....#... +.......##..#......#...#......## +#####.....#........#.#.......#. +.....#...#..#...#.#.....#..#... +....#...#....##.....##....#.#.. +.#..#......#.####.....#....#..# +...#.......#..#.....##........# +.#.....#.#.#.....##...#..#..... +.............#...#..#.....#.... +...#.....##.......#...##..#...# +..#.............#...#..#..##... +...#........#........#...#...#. +##..........#.#.#.............# +....#....#..............#..#... +....#..####..##....#.......#.#. +.#..#.....##....#.#.....#...#.. +#............##..#..#.#......#. +....#..........##..#........... +..#.##.#.......#...#.##....#... +....#.#.............#.#.##....# +...#..#.#.#......#..#....#....# +.............#...........#..#.. +#.............##.......#..###.. +..##....#.#.#...#...#....#...#. +##.......####........##..#..... +.###..#..#..#..#...#.#......... +............#............#..... +#...#.....#.#.##.##...#.......# +#........#....#...#.........#.. +#....#.#......#.............#.. +....#............#......##...#. +.......#........#..#.......#..# +#.#...#.#.#..#..#........#....# +#.#.##...........#.....#.....#. +.#...##.#..#................... +###...#.#.....................# +.#....##...##.#....#..#........ +........###...#.#....##...#..## +...#..#..........###..#.......# +..#..##.............#.....#.... +....##..#..............#....... +...##...##.#....#.#...#...#.#.# +..#..........#.....##........#. +.#.#.....#......#..#....#...... +...##.#....#.......#......#.... +...##..#........##......#..##.. +#..###...#...........#.#....... +..##...#...#.#.#...#.#.....#... +..#.....##.#....#.....#..#..... +..#.#......#.......#........... +....##......##.............#..# +.......#.........##...#..#...#. +.#........#.##.#.....#.#....... +#..#...#..#.....##...........#. +..##..............#....#....... +.#..#....#.#...........#..##.#. +#....#..###..........#...#..... +.......#...##........#.#...###. +....#..#......##......#.....#.. +.#..##..#..#......#......#.##.. +....#.#...........#..#.#.##.#.. +.....#......#.....#.....#..#... +..........#...........#...##... +#..#.#.#..#....#.....##......## +..#.....#.....#................ +...#.#..##.........#..#..##.... +.#.....##..#.#.#.#.....#....... +...........##...#.............. +...#.#....##..#.............### +...#.#...........#.........#... +#.....#.....##..#.#.#.#....#... +##..................##.##...... +......#.....#....#.....#..#...# +.............#.......#....#..## +.#..#.##..#..#.........##...#.. +..#.#....#........#....#....##. +.#.#.#.#.#.......#.......#..#.. +#.....#..##..#.........#....... +.............#.#..............# +.........#......#....#.#......# +.........#.#...##..#.#......... +...........#..........#........ +.......#...#...#......#..#..... +#.....#...............#.....#.# +..#....#..........#.#...#..#... +#....##..#..#.....#.#..#.#..... +.#....#..###............##..... +......#.##...........#....#..#. +...#........##....#...#...#.... +..#.#.#.....#..#.#..........##. +..................#...........# +##........#.#......#.#.......#. +......#..#.............##...... +.#..###..#...###......#....#..# +..#...........#...#...##..#...# +..#..........#..............#.. +.....#......................... +..#.#..##...........##...#..... +...........#......##.....##.... +......#.......#................ +.........#.......#.#........... +#......#...#........##.....##.. +...#.....#....#..#.....#....... +....#.#......#...#..#.##.##...# +..#..#.#.....#...#...........#. +.#....##.####.....#..........## +...##.##.....##..###...#....... +.......#.#...#....#.......#..#. +.#..#.###.#.............#...... +.###.........####..#........... +#..#.#.###.....#.......#....... +.#.....#.....#.....#.........#. +..#...#......#.......##.###.... +.......##.............##.#..... +.....................#.....##.# +##.#...#........#..##........#. +...#..........#.#.#..#......### +.#....#.#.#..........##........ +....#....####....#.#....#..#.#. +..#.........#....##..........## +...##.#.......##.#.......#.#... +........#..#......#...#.#.....# +.....##............#.#.......#. +.........##...##..#.....#..#... +#...#....#........#...#....##.# +..#.....#..........#...##.....# +.##..#.........#...........#... +.....##.#.#.#.#..#...#.....#.#. +.#..#..##.........#.......#...# +#....#.....#...#....#.........# +...#..#.......#.........#...... +.#....##..#......##.#.#......#. +....##.##...........#...#...... +..#.#....#.##...#......#....... +...#........#.............#.... +...##....................#.###. +.#.......#.........#......##... +....#..#..............#....#... +....##.#............#.......... +.#...#....#...##..........#.... +....#............#.....#....... +.......#........#.............. +....#.#....#.#..#..#........... +......................#.#...... +#......##.....#..#.......##.... +...#........#........#.#...##.. +##.#....##....#................ +#..#....#..............#.##.... +......#........#...........#... +#....##.##...#...#..#...##..... +............#............#..#.. +#....#...#..#..#.#...........#. +.......#..........#..........## +.....#......#....##.#.......... +.#....#....#....#....#..#...#.. +.....###....#...#.#.#........#. +.......#...#..........##..#...# +..##........................##. +.....#....#..............#....# -- cgit v1.2.3