aboutsummaryrefslogtreecommitdiffstats
path: root/day3
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2020-12-03 10:14:36 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2020-12-03 10:14:36 +0200
commit3091e8ba5d3eb34a53da72edf53291a9d40251fd (patch)
treef64de56de845176558a6cec7f6c0ff213a8d9d07 /day3
parent46054b550ece116324332e58f97434a4a50848ca (diff)
Solve 3.1
Diffstat (limited to 'day3')
-rw-r--r--day3/index.ts31
-rw-r--r--day3/input-test.txt11
-rw-r--r--day3/input.txt323
3 files changed, 365 insertions, 0 deletions
diff --git a/day3/index.ts b/day3/index.ts
new file mode 100644
index 0000000..6dd8168
--- /dev/null
+++ b/day3/index.ts
@@ -0,0 +1,31 @@
+import { Observable, of } from "rxjs";
+import { concatAll, count, filter, map, take, tap } from 'rxjs/operators';
+import { ExerciseModuleFunc } from "../types";
+
+type Coords = [number, number];
+
+const day3: ExerciseModuleFunc = async (input: string) => {
+ const lines = input.split("\n");
+ const my = lines.length;
+ const mx = lines[0].length;
+
+ const isTree = (x: number, y: number): boolean => lines[y][x % mx] === "#";
+
+ const indexObs = new Observable<Coords>(sub => {
+ for (let y = 0, x = 0; y < my; y += 1, x += 3) {
+ if (isTree(x, y)) {
+ sub.next([x, y]);
+ }
+ }
+ sub.complete();
+ })
+
+ const prom1 = indexObs.pipe(
+ tap(console.log),
+ count()
+ ).toPromise();
+
+ return Promise.all([prom1]);
+}
+
+export default day3;
diff --git a/day3/input-test.txt b/day3/input-test.txt
new file mode 100644
index 0000000..8f551de
--- /dev/null
+++ b/day3/input-test.txt
@@ -0,0 +1,11 @@
+..##.......
+#...#...#..
+.#....#..#.
+..#.#...#.#
+.#...##..#.
+..#.##.....
+.#.#.#....#
+.#........#
+#.##...#...
+#...##....#
+.#..#...#.# \ No newline at end of file
diff --git a/day3/input.txt b/day3/input.txt
new file mode 100644
index 0000000..43deaca
--- /dev/null
+++ b/day3/input.txt
@@ -0,0 +1,323 @@
+......#..##..#...#...#.###.....
+#..#............#..........#...
+..........#....#..........#....
+....#..#.#..........#..#.....#.
+#.......#...#......#........###
+#####........#.#....##..##..#..
+......#.#..#..#..##.#..#.##....
+.#..#.#..............##....##..
+..##......#....#........#...###
+...#....#.#....#.#..#......#..#
+..................#.....#.....#
+#.#...#...#....#............#.#
+.#...#.....#...##........#.....
+...#....#........#..#....#..###
+#...##.....##.#.#...........#.#
+.###........#.#.#.........#....
+...#.............###.....#.#..#
+.####.#..#....#.....#.........#
+.#.#........#.#.....#.....#....
+.#.......#................##.##
+...#.#..#...###.....#....#..##.
+...#....##..#............##...#
+#...#............######...#.##.
+.........#........#.#...#..##..
+.....###..#.#.....##.#.#......#
+..#.#...#.#..#.#.##..#.....#.#.
+..#......#.#....#...#..........
+..#...#.....#.#...##.....#.....
+.##...........####........##...
+....#............#.#...........
+.....####.........#.##....###..
+#..#..#.#..............#.#.....
+...#.#........#.........#......
+......#.#.#...#.....#....#.....
+........#.#...#####..#..#......
+.....#.#....#....#...........##
+.#...#.........#.......##......
+.#.##..##......#...............
+...#.....#.......#.#.#.........
+.........#..#...#...#.#.##....#
+.#......##....#..#.........#...
+....#.....#........#.........##
+......#...........##...........
+.....#..............###.#....#.
+........#..#...#..#..#..#..#.#.
+.#.....#.##.#..#..#.#.....#....
+...#....#...#.#.....##.#...#..#
+#..#......#..#.###...........#.
+.##...##.#........#.#......#.#.
+...#.#..#.#.......#..###...##..
+#.......#.#....#..........#....
+.#.....#..#.#.#..#..#........#.
+.#...#......#.#...#.##.....#.##
+...######..#.#....#.........##.
+#.#.......................#....
+..#..##...#...#.#..##.......#..
+.##..#.......##......##.#..#...
+#.#....##.......#..#...........
+..#...#............#..#........
+........#.#.........#...#..#..#
+.#...###...............##...#..
+...........#.....#....#....###.
+#..#....##..#................##
+...#.#..#..##......#....##....#
+...#.##...#....#..#....#.......
+#...##..##.#.........#...#....#
+.##........###.#..........#....
+..#..#..#...#.##..#.#......#...
+.......##..#....###.##.....#..#
+#....#...#.#.....#..###....##..
+.#.......#.........#....#.#..#.
+.........#.......#.#.......#...
+..........#...##..#...#....#.##
+..#........#.......#...........
+#....#.....##......#....#.#...#
+......#.....#....#.....#..#....
+.#....##...#...##..............
+..#....#......#...#....#...#...
+#....###...##..#.#....##......#
+..#.......#.........#..#......#
+...#...#.##.......#....##..#...
+..#.#...#.##..#..#..#...#.#...#
+.#.........###....#....#.....#.
+.#.##.#..##..#...........#....#
+....##..#..##.#.......#....#..#
+....#..#.........##..#......#.#
+..........#.#.#....##.#......##
+.##...#....###...#..........#..
+#..#.....#..#.#.#.#..#......#.#
+......#....#......##.#......#.#
+...#.....#.......#....#.......#
+.#.#................#..........
+......#..#..#...............##.
+##......#...#.####....#.#.#....
+...#..##............#....#.....
+..#..#.#...#..................#
+.##.#.#..##.###.....#..#.......
+..#...#.#...#......#..#........
+.###..........##...###..##..#..
+#.#...#........#.......##......
+..##...#........#....##...##...
+.......#.##.....#.#.##..#..##..
+........#............#....##...
+...#.#.#..#.........#.#.......#
+..#..##.##...#.##...#....#...#.
+.....##.#...##............##...
+.#...#.###....#.......#...#...#
+.......#######.#....#.....#.#..
+......#.......#............##..
+.....#...........#......#.....#
+........#....#.##.#............
+.#........#.......##.#.#....#..
+#.....#..####.#................
+.....#.......................##
+.#.....#..##.#..##........#.#.#
+#...##....#..##................
+......##.###..........#.....#..
+.#........#...#..............##
+..#..........###.........#.....
+....#.....##....#..#..#.#.#....
+....#.......#.##...#.####.#....
+#........#............#.##.....
+..#......##.....#..#...#.......
+..#......###...#.##......#..#..
+#..#..#............#..#.###....
+...##.........#..##...#..#.#...
+..#.###..#.##.#........#..#....
+......#..###.#........#........
+.#....#.#..#.....#..#..#.......
+#.....##.##...#...###.#.#..#.#.
+.#....#..#.........#..#....###.
+......##.####...#....#........#
+##..#........#..#..##...#......
+#.........#.........#...#..#.#.
+..........#...................#
+###....#....#....#......###...#
+#....##........#..###.#..#.....
+.#......#.....#.#.........#..#.
+...#.......##.....#.........###
+..............#........#.....##
+....#.#..#.....###.#....##.....
+.........#..##.#....#.#........
+...#....#.......#.#.#..#.#....#
+...........#...#..........#.#..
+#.................##........###
+####..#.#..#...#.....###.......
+..#.#......##.#.......#........
+.......##........#..#.....#..#.
+...#..#......#..#.#.......###..
+#....#...##..#.#.#.#.........#.
+....#....#....#.#..#..........#
+...###........#.#.###......##..
+................#.....#.#...##.
+..#..#.###...........#...###.#.
+.........................#..#.#
+#...#..#..##.###.....##.##.#...
+...#..................#.#....#.
+......#..##.#.......#.......#..
+.##....#.#................#....
+.#...#..#.#.#....##....#.......
+.##......#.....#..........#....
+..#...........#..##.........#..
+....#.#...........#..........##
+....#.#.#...........#.#........
+......#.....#..#....##....##...
+............##...##......#.#.##
+#.#.....#..#....#..#...#.#...#.
+.#...###..#..#.......#.......#.
+.....#..#.##.....#....#...#....
+##.....#..##.......##..#.#.#..#
+....#.#......##....#.....#..###
+.#...#.#......#.##...#..##.....
+.#...#...#......##..#..#...#.#.
+.#.........#....##...###...##..
+###.....#......####.....#.#....
+.....#..##.##................#.
+.#.................#...#..##.#.
+....#....#..#.......#.....#....
+.##....#..#..#.....###.#..#..#.
+#.#.......#.....##...#.....#...
+#.#........#.#.###...#....#....
+.#.....#.....##.#...#..#.......
+..###.#............#...##.###..
+.....#.....#..#..##............
+.#.#..#.#..##..#....#...##.....
+.#...........#..#.......#...#.#
+#.#.#.#.....##....#............
+...#.................#.#......#
+.....##.............#...#.#....
+.##......#.#....#..........#.#.
+.#.##.......##...#...#.....#.#.
+#...#.#........#......##....#.#
+#....##....#....#...#..#..#.#.#
+......#..........#...#.....#..#
+#..#....#....#..##.#..#.#...#..
+......#..#.#....#.....#.#..#..#
+...#.#...###........#.#......##
+..#............................
+...#.#..##...##...#...#......##
+...#.####......#.........#....#
+.#...#.#...##....#......#.#....
+.#.....##..##.#................
+.#...............#.............
+......#.....#...#..##..##......
+...#..##.......#.......#..#.#.#
+......##.....#..#.....#...#.#.#
+........##........#.#........##
+.#....#.....###..#.......#...#.
+#...#....#.........#.......#...
+...##..#........#####.#........
+###..#....#.#..#...#.####......
+..#..........#.#.............#.
+#......#.#....#.#.#....#.##....
+.#.#.#.............#....#...#..
+......#.....#.#...#..###.#..#..
+.....#..#............#...#...##
+..#......###..#........#.#.....
+#..##......#.#.#.#...........#.
+#..#...##.##.....#....#..#.....
+...##.#..........#.#....#...#..
+.#.#.#.#..#.#...#......#.......
+....#......###.#...............
+.........#...#....#...#.#....#.
+##.#.........#...##............
+........#..........#.#...#.....
+..#........#....#.......#......
+#..#...............#..#...##.#.
+#........#.....##.#..#....#...#
+..##....#....#.#...........##..
+....#.#.........#..#.....#..#..
+.......##....#.#.#....###.#....
+......#....#.#...#..#.........#
+.....##..#....#.#......#.#.#...
+#.##..##.#.......#..#...##.#.##
+........#.#..#...##.#.#..#.....
+#..#......#......#...#.#..#....
+.....#......#.#....##....##....
+....#.##...##..#..........##.#.
+.#....#.......#.........#......
+.#.......#.#...#...............
+....#.##.......#.##..#.##..#...
+#..#.......#.....#..#..........
+..#.##.......#....#.#..##..#...
+.#.....#...##.#.#..#...#.......
+.......#.........#......#.#....
+#.##.....##.......#....#.......
+##.#.#.........##..#.....#....#
+....#.#.#.#....#..#..##.......#
+#...#...........#.#............
+...#...#.#..#..##..............
+......#.......#.........#..#.#.
+#.....##.#....#...#..#.........
+#...#..###.##..###...##.....#..
+#....#.#.#...#.#..........#....
+................#.#....#.....##
+#.##..............####.....#.##
+................#.....#........
+#...#..#......#.....#......#...
+.........##...........#...#...#
+#.#....#...##.....#.....#..#..#
+.....#...##..##.............#..
+....###.#.......#.........#...#
+..#.......#......#..#...#.#....
+#.#....#......#.##....#.##.#...
+.#.#...#.......#.#...#.##..#...
+..........#......#.....#.......
+........#...#.....#...##...#.#.
+.....##....#.##..#........#.##.
+..........##.....#..#........#.
+.#....#..#.......#.##..........
+.#..#..#...#...#........#.##...
+.#...#.##.......#...#........#.
+.....#....#.............#..#...
+...#....##...#...#.....##......
+#.#####.........##...#.....#...
+......#.......#....#.....#..#..
+..#..............#.#..#..#.....
+....#.................#...#....
+###.#..##.#....#...#.#......#.#
+..##......#.#........#.#...##..
+.....#...#...#..#.#..#..##..#..
+.##...#......#...#...##.#...#..
+.......###.#...........##.##...
+.#.##..#.#.###.......#..##...#.
+..#....#.......#..##......#....
+.#....#.#..#..#.#.#....#...#...
+..........##....#....#.#.......
+.....#.......#.#..###.#.###....
+.#.#....#.##..#.#..#.....#.#.#.
+....#.....#.#.#............#...
+.###....#...##......##..###..#.
+...#.#..#.....#...#....##..#...
+.#.#....#..........#...##.....#
+#.....##...#........#.#..##..#.
+.......#....#.#..........#...#.
+.........#..#.#.###.........##.
+..................#.#....#....#
+....#....#.#..#.......###.##.##
+....#...#.................#....
+...#..#####.......#.#..##.##...
+##.#....#...............#..#...
+....#..........#...........#.#.
+..##.#.##.#..#.#....#..........
+.....#....#....##.#....#....#.#
+.......#..##.....###...#....#.#
+.#.......#..#.#.#...........#..
+.#...........##.#.##....#.#....
+....#.#....#.#.#......##.......
+.........##......#.#.....###...
+........#.#...#.##.....#.##.##.
+##.#..##.#.........#....#......
+.#.#.#....#..........#.#....#..
+....###.........#.#.#..........
+#..#....##.....#...............
+#.##....#.#...#.....#......#.#.
+............#.##........#......
+.....#.#.....##..##............
+.##..........#.......#......#..
+...##..##......#.....#..#....##
+.##.##...#.................##..
+#....#.#........#..#....#..##.#
+....##..##......#....###.#.#..#
+.....#....#..#..#...##...#...#. \ No newline at end of file