Skip to content

Commit

Permalink
Day 23 part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
NullDev committed Dec 23, 2024
1 parent a3ff9b5 commit 6362c6a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
23 changes: 23 additions & 0 deletions 2024/Day_23/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,26 @@ td,wh,yn
```

Find all the sets of three inter-connected computers. **How many contain at least one computer with a name that starts with `t`?**

---

## --- Part Two ---

There are still way too many results to go through them all. You'll have to find the LAN party another way and go there yourself.

Since it doesn't seem like any employees are around, you figure they must all be at the LAN party. If that's true, the LAN party will be the **largest set of computers that are all connected to each other**. That is, for each computer at the LAN party, that computer will have a connection to every other computer at the LAN party.

In the above example, the largest set of computers that are all connected to each other is made up of `co`, `de`, `ka`, and `ta`. Each computer in this set has a connection to every other computer in the set:

```
ka-co
ta-co
de-co
ta-ka
de-ta
ka-de
```

The LAN party posters say that the **password** to get into the LAN party is the name of every computer at the LAN party, sorted alphabetically, then joined together with commas. (The people running the LAN party are clearly a bunch of nerds.) In this example, the password would be **`co,de,ka,ta`**.

**What is the password to get into the LAN party?**
24 changes: 19 additions & 5 deletions 2024/Day_23/part_1.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,30 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
// = Copyright (c) NullDev = //
// ========================= //

/* eslint-disable no-sequences */

const INPUT = String(fs.readFileSync(path.join(__dirname, "input.txt"))).trim().split("\n");

const pStart = performance.now();

//
// YOUR CODE HERE
//
const result = "...";
const res = [
...new Set(
(adj => Object.keys(adj).flatMap(n =>
[...adj[n]].flatMap((nx1, i, nxList) =>
nxList.slice(i + 1).filter(nx2 => adj[nx1].has(nx2))
.map(nx2 => [n, nx1, nx2].sort().join(",")),
))
)(INPUT.filter((x, i, arr) => !arr.some((y, j) =>
i > j && y.split("-").reverse().join("-") === x,
)).map(l => l.split("-")).reduce((acc, [a, b]) => (
((acc[a] = (acc[a] || new Set()).add(b)) || 1) &&
(acc[b] = (acc[b] || new Set()).add(a)),
acc
), {})),
),
].filter(e => e.split(",").some(n => n.startsWith("t"))).length;

const pEnd = performance.now();

console.log("<DESCRIPTION>: " + result);
console.log("SETS WITH AT LEAST ONE T-NODE: " + res);
console.log(pEnd - pStart);

0 comments on commit 6362c6a

Please sign in to comment.