const fs = require('fs'); const input = fs.readFileSync(__dirname + '/input.txt', 'utf8'); const connections: { [key: string]: Array }= {}; input.split("\n").forEach((conn: string) => { const [c1, c2] = conn.split('-'); connections[c1] = [c2, ...(connections[c1] || [])] connections[c2] = [c1, ...(connections[c2] || [])] }); const tCs = new Set; for (let key in connections) { const conns = connections[key]; if (key.startsWith('t')) { conns.forEach((c2) => { connections[c2].forEach((c3) => { if (connections[c3].includes(key)) { const arr = [key, c2, c3]; arr.sort(); tCs.add(arr.join(',')); } }) }) } } console.log(tCs, tCs.size);