const { readInput, sum } = require("./util"); const { paragraphs } = readInput(); function intersect(strA, strB) { const setB = new Set(strB); return strA .split("") .filter((el) => setB.has(el)) .join(""); } function intersections(...strings) { let res = strings[0]; for (const cur of strings.slice(1)) { res = intersect(res, cur); } return res; } console.log("Part1:"); console.log(sum(paragraphs.map((p) => new Set(p.replaceAll("\n", "")).size))); console.log("Part2:"); console.log(sum(paragraphs.map((p) => intersections(...p.split("\n")).length)));