summaryrefslogtreecommitdiff
path: root/day3
diff options
context:
space:
mode:
authorCody Hiar <cody@hiar.ca>2021-01-25 12:34:50 -0700
committerCody Hiar <cody@hiar.ca>2021-01-25 12:34:50 -0700
commit34f71edd66e22b7d1e1b262d92d80e1bf335aa57 (patch)
treeab37eb9345f859b1de50aba7869ea39e35b700a1 /day3
Initial commit
Diffstat (limited to 'day3')
-rw-r--r--day3/day3.py35
-rw-r--r--day3/input323
2 files changed, 358 insertions, 0 deletions
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 @@
+.....#....#...#.#..........#...
+...#.................#.........
+......#...#.#.#.....#..#.....#.
+.........#.#.............##....
+#..####..#..#.##.....#.........
+...#........#..##...........#..
+..##.#.#..#....#..#......#.#...
+.......#.##....#.....###....#.#
+.#..#...#......#..#....##.#....
+...#...............#.#.....#...
+..#............#..#.........#.#
+#.#.#.............##.#......#..
+#...#..............##...#.#....
+...#....#................#.#..#
+..#.#..#.#.#..#.....#.........#
+#.............#..#..........#..
+.#...#.#........###.#....#...#.
+#......#....#.#..#.##..#.......
+.##......###.#......#..##...#..
+#..#....#........#......#.#....
+.#..................#.....#.###
+.#......#.#.#.....#...#.#......
+....#.............#.#..........
+....#..#.#........#..###.......
+.....#....#...#........#.......
+...........#.###....##.......#.
+....#...........#.#..#...#.....
+...........#.....#.#...........
+.....#........#.....#.#..#....#
+#.#......#.......#.......#.....
+..........#.............#.#.#..
+#...#..........#....#....#.....
+.#.#......#..##...#.....#...##.
+.#....#...#.#.......#.#........
+....#....##.##...#.............
+#...#....#..#.........#........
+...#.....#.#...#.......#..#....
+#.......#...#....##........#..#
+####........#........#....#.#..
+............##..........#......
+.......#.....#.#.#.##..#...#...
+..........#....#...##.........#
+..##..####.......##......#.##..
+.....#.#......##...#..#...#....
+....#.#.#.........#........#...
+...........###...#.........##..
+.......#.#....#......#.##...##.
+.................#...##.#...##.
+.......#.......#..#.#..........
+.#....#..#....#........#.......
+...............#.##..#...##..#.
+.###.#....#......#...#.#.....#.
+.#.....##.......#.......#......
+....#..#.....#.....#...........
+.......#....#.................#
+.......#.##...#...#......#.....
+.#.....#...####.............#..
+......#.........#..........#...
+.........#....#....#........###
+....#.........#......##.....#..
+....#........##...##.....##...#
+.#..#....#..........#...#.###.#
+#..#......#...#........#.......
+...#.........................#.
+.............#........#........
+.......#.#.#.....##.....#..#...
+..##..##.........#.............
+.#...#..#......#...##..##..###.
+.....#....#...#...##.##........
+.#.#..#...........#..#..#......
+##..#...#..#...##..#....#......
+...#...#...#.........#....###..
+...##..#....#.#.#.......#...#..
+..#.#.....#..#....#..##.......#
+.....#.#.....#......#....#.#...
+.......##....#.....#...#.....#.
+..##..#.................#.#....
+..............##....##.#..##...
+.#..#.....#....#.#.#...........
+......#.#.#..#..#...#.....#..##
+..#.........#.#.......###...##.
+#.....#...........#.....#.##.#.
+#..........#....#....#..#....#.
+.#.....#...#.......###......#..
+....##..##......#....#....#....
+.......#.#.............#....#.#
+.#..#.##.##.##....#.#.....##.##
+....#..##.#..#.............##..
+....#...........#...#....#..#..
+...........#..#....#....##.#.##
+......#....#....#.....#......#.
+.##.##....#.....#.#......#...#.
+.....##.......#.#.#........##..
+#..........##..#....#..#.#....#
+...#...........................
+...#..#...#..#.#.#.#.......#.#.
+.....#.........#..###..........
+...#.#......##....#......#..###
+#..............#....#.......#..
+.........##......###..###......
+..#......##...........#.##.....
+#.#..#......#...##.............
+......#.#.............#....#..#
+#.....##..#.#.................#
+..##....#.....#....#.....###...
+.#.#.##.....#..................
+.#......#.#.#.....#..#....#....
+..#.#.....##.#...#..#.#.##.....
+..#.#..#......##.#.#..........#
+.......##.....#..#...#....##.#.
+...#.....#..........#..........
+......................##......#
+...###.........##.........#....
+....#..................#.....#.
+.##..#.............#........##.
+....#....#...###..........#....
+.....#.#..........###..........
+..#......##......#.#.##.#..#...
+##...........#.#..#.....#..#...
+.........#......#..........#.#.
+...#.##.#..#..###..#...........
+....##.#.##...........#.....##.
+....#...................###....
+#.......#......#......#.....#..
+#..........##..................
+...#..#.#....#..#.........##.#.
+......#...##.#...............#.
+.........#....#.#...#..#..#....
+...#......###..#......#.....#.#
+#..###.#.............#.........
+......#...........#............
+..#..#.##.....#......#.#..#...#
+.........#..............#......
+........#.....#..#...#.....#..#
+.....................#........#
+.##.......##...#.###.........#.
+.#...#.......#.#....##....#....
+........#......#...........#.#.
+....#......##...#.....#...#...#
+..#.........#.#...............#
+....#.....#......#.............
+.............##.....#....#.....
+........#......#.#.....#....#..
+#.........#...#......#....#...#
+.#........###...#.#.#...#....#.
+.###...........#..#............
+....##.........#..#...##.#..###
+.####..#.#...............##.#..
+#.....#...#....#.......##....#.
+..#.....##...##.#...#..#.......
+..#.###.......#.....#.......#..
+...........#.......#....##....#
+..#...#....##........###......#
+...#..#..............#...#.....
+##.#.............#....##.#..##.
+##.#..#..............#.#.......
+.......#....#....##............
+.##..##.#..........#.#...#.#...
+.........##.......##...#...#...
+............#...##....#...#....
+........#...#..#...#.##......#.
+..#...#.#.........#.#....#.....
+..#...#.#..#.......#.#.........
+.......#.....#...#.#..###....#.
+.#......#.#....#.#.####....#...
+.......##..#......#...#......##
+#####.....#........#.#.......#.
+.....#...#..#...#.#.....#..#...
+....#...#....##.....##....#.#..
+.#..#......#.####.....#....#..#
+...#.......#..#.....##........#
+.#.....#.#.#.....##...#..#.....
+.............#...#..#.....#....
+...#.....##.......#...##..#...#
+..#.............#...#..#..##...
+...#........#........#...#...#.
+##..........#.#.#.............#
+....#....#..............#..#...
+....#..####..##....#.......#.#.
+.#..#.....##....#.#.....#...#..
+#............##..#..#.#......#.
+....#..........##..#...........
+..#.##.#.......#...#.##....#...
+....#.#.............#.#.##....#
+...#..#.#.#......#..#....#....#
+.............#...........#..#..
+#.............##.......#..###..
+..##....#.#.#...#...#....#...#.
+##.......####........##..#.....
+.###..#..#..#..#...#.#.........
+............#............#.....
+#...#.....#.#.##.##...#.......#
+#........#....#...#.........#..
+#....#.#......#.............#..
+....#............#......##...#.
+.......#........#..#.......#..#
+#.#...#.#.#..#..#........#....#
+#.#.##...........#.....#.....#.
+.#...##.#..#...................
+###...#.#.....................#
+.#....##...##.#....#..#........
+........###...#.#....##...#..##
+...#..#..........###..#.......#
+..#..##.............#.....#....
+....##..#..............#.......
+...##...##.#....#.#...#...#.#.#
+..#..........#.....##........#.
+.#.#.....#......#..#....#......
+...##.#....#.......#......#....
+...##..#........##......#..##..
+#..###...#...........#.#.......
+..##...#...#.#.#...#.#.....#...
+..#.....##.#....#.....#..#.....
+..#.#......#.......#...........
+....##......##.............#..#
+.......#.........##...#..#...#.
+.#........#.##.#.....#.#.......
+#..#...#..#.....##...........#.
+..##..............#....#.......
+.#..#....#.#...........#..##.#.
+#....#..###..........#...#.....
+.......#...##........#.#...###.
+....#..#......##......#.....#..
+.#..##..#..#......#......#.##..
+....#.#...........#..#.#.##.#..
+.....#......#.....#.....#..#...
+..........#...........#...##...
+#..#.#.#..#....#.....##......##
+..#.....#.....#................
+...#.#..##.........#..#..##....
+.#.....##..#.#.#.#.....#.......
+...........##...#..............
+...#.#....##..#.............###
+...#.#...........#.........#...
+#.....#.....##..#.#.#.#....#...
+##..................##.##......
+......#.....#....#.....#..#...#
+.............#.......#....#..##
+.#..#.##..#..#.........##...#..
+..#.#....#........#....#....##.
+.#.#.#.#.#.......#.......#..#..
+#.....#..##..#.........#.......
+.............#.#..............#
+.........#......#....#.#......#
+.........#.#...##..#.#.........
+...........#..........#........
+.......#...#...#......#..#.....
+#.....#...............#.....#.#
+..#....#..........#.#...#..#...
+#....##..#..#.....#.#..#.#.....
+.#....#..###............##.....
+......#.##...........#....#..#.
+...#........##....#...#...#....
+..#.#.#.....#..#.#..........##.
+..................#...........#
+##........#.#......#.#.......#.
+......#..#.............##......
+.#..###..#...###......#....#..#
+..#...........#...#...##..#...#
+..#..........#..............#..
+.....#.........................
+..#.#..##...........##...#.....
+...........#......##.....##....
+......#.......#................
+.........#.......#.#...........
+#......#...#........##.....##..
+...#.....#....#..#.....#.......
+....#.#......#...#..#.##.##...#
+..#..#.#.....#...#...........#.
+.#....##.####.....#..........##
+...##.##.....##..###...#.......
+.......#.#...#....#.......#..#.
+.#..#.###.#.............#......
+.###.........####..#...........
+#..#.#.###.....#.......#.......
+.#.....#.....#.....#.........#.
+..#...#......#.......##.###....
+.......##.............##.#.....
+.....................#.....##.#
+##.#...#........#..##........#.
+...#..........#.#.#..#......###
+.#....#.#.#..........##........
+....#....####....#.#....#..#.#.
+..#.........#....##..........##
+...##.#.......##.#.......#.#...
+........#..#......#...#.#.....#
+.....##............#.#.......#.
+.........##...##..#.....#..#...
+#...#....#........#...#....##.#
+..#.....#..........#...##.....#
+.##..#.........#...........#...
+.....##.#.#.#.#..#...#.....#.#.
+.#..#..##.........#.......#...#
+#....#.....#...#....#.........#
+...#..#.......#.........#......
+.#....##..#......##.#.#......#.
+....##.##...........#...#......
+..#.#....#.##...#......#.......
+...#........#.............#....
+...##....................#.###.
+.#.......#.........#......##...
+....#..#..............#....#...
+....##.#............#..........
+.#...#....#...##..........#....
+....#............#.....#.......
+.......#........#..............
+....#.#....#.#..#..#...........
+......................#.#......
+#......##.....#..#.......##....
+...#........#........#.#...##..
+##.#....##....#................
+#..#....#..............#.##....
+......#........#...........#...
+#....##.##...#...#..#...##.....
+............#............#..#..
+#....#...#..#..#.#...........#.
+.......#..........#..........##
+.....#......#....##.#..........
+.#....#....#....#....#..#...#..
+.....###....#...#.#.#........#.
+.......#...#..........##..#...#
+..##........................##.
+.....#....#..............#....#