aboutsummaryrefslogtreecommitdiff
path: root/2020/06/solve.js
blob: c3907cfe4c2906bf2bc8b529e0a41cb6fa63c6c9 (plain) (blame)
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
30
const { _, performance } = require("perf_hooks");
const fs = require("fs");
const data = fs.readFileSync("input", "utf8");

function part_one()
{
    return data.split("\n\n").map(e => [...new Set(e.replace(/\n/g, ''))].join('').length).reduce((a, b) => a + b);
}

function part_two()
{
    let res = 0;

    data.split("\n\n").forEach(elem => {
        const line = elem.replace(/\n/g, '');
        const chars = line.split('');
        const cnt = elem.split('\n').length;
        for (const c of new Set(line))
            if (chars.filter(x => x == c).length == cnt)
                res++;
    });

    return res;
}

const tic = performance.now();
console.log(part_one());
console.log(part_two());
const toc = performance.now();
console.log("TIME: " + ((toc - tic) / 1000).toFixed(6) + " seconds");