From 239d4e44f6e8bc49aedea6462eb12c7a9742811f Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Mon, 7 Dec 2020 12:51:18 +0200 Subject: Solve 6.1 --- day6/index.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 day6/index.ts (limited to 'day6/index.ts') diff --git a/day6/index.ts b/day6/index.ts new file mode 100644 index 0000000..612aebf --- /dev/null +++ b/day6/index.ts @@ -0,0 +1,29 @@ +import { of } from "rxjs"; +import { concatAll, map, reduce } from 'rxjs/operators'; +import { ExerciseModuleFunc } from "../types"; + +type Group = string[]; + +const getUniq = (group: Group): Set => { + const joined = group.join("").split(""); + const set = new Set(joined); + return set; +} + +const day6: ExerciseModuleFunc = async (input: string) => { + const splitted = input.split("\n\n"); + const groups: Group[] = splitted.map(g => g.split("\n")); + + console.log(groups); + + const prom1 = of(groups).pipe( + concatAll(), + map(getUniq), + map(res => res.size), + reduce((acc, val) => acc + val) + ).toPromise(); + + return Promise.all([prom1]); +} + +export default day6; -- cgit v1.3