aboutsummaryrefslogtreecommitdiffstats
path: root/day6/index.ts
blob: 612aebfa8a2bf70f8ed0b0dc4145aa18e9d4e1f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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;