From 3091e8ba5d3eb34a53da72edf53291a9d40251fd Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Thu, 3 Dec 2020 10:14:36 +0200 Subject: Solve 3.1 --- day3/index.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 day3/index.ts (limited to 'day3/index.ts') 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(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; -- cgit v1.3