diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2020-12-07 12:51:18 +0200 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2020-12-07 12:51:18 +0200 |
| commit | 239d4e44f6e8bc49aedea6462eb12c7a9742811f (patch) | |
| tree | 514d8386f9f29385a8fb9bfbbfe19792b43337cb /day6/index.ts | |
| parent | ea972bbc868c9fbfada2acb6b4e6cdaebcc6e24c (diff) | |
Solve 6.1
Diffstat (limited to 'day6/index.ts')
| -rw-r--r-- | day6/index.ts | 29 |
1 files changed, 29 insertions, 0 deletions
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<string> => { + 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; |
