Skip to content

Commit

Permalink
Day 23 part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
NullDev committed Dec 23, 2024
1 parent 6362c6a commit 488a855
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
29 changes: 24 additions & 5 deletions 2024/Day_23/part_2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,35 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
// = Copyright (c) NullDev = //
// ========================= //

/* eslint-disable no-sequences, no-param-reassign */

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

const pStart = performance.now();

//
// YOUR CODE HERE
//
const result = "...";
const res = ((
m, bk = (R, P, X, mat, cliques = [], cList = new Set(P)) => ((P.size === 0 && X.size === 0)
? [[...R]] : (cList.forEach(v => (((cliques = cliques.concat(bk(
new Set([...R, v]),
new Set([...P].filter(x => (mat[v] || new Set()).has(x))),
new Set([...X].filter(x => (mat[v] || new Set()).has(x))),
mat,
))) || 1) && P.delete(v) && X.add(v))), cliques)),
) => bk(new Set(), new Set(Object.keys(m)), new Set(), m)
.reduce((max, clique) => (clique.length > max.length ? clique : max), [])
.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
), {}),
);

const pEnd = performance.now();

console.log("<DESCRIPTION>: " + result);
console.log("LAN PARTY PASSWORD: " + res);
console.log(pEnd - pStart);
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ I also tried to experiment with a couple of different things:
- Sloppy, hacky, small, quick & dirty dijkstra in [Day_16/part_1.js](https://github.com/NullDev/Advent-of-Code/blob/master/2024/Day_16/part_1.js)
- _Almost_ One-Liner [BFS](https://en.wikipedia.org/wiki/Breadth-first_search) in [Day_18/part_1.js](https://github.com/NullDev/Advent-of-Code/blob/master/2024/Day_18/part_1.js)
- [DP](https://en.wikipedia.org/wiki/Dynamic_programming) One-Liner with memoization in both [Day_19/part_2.js](https://github.com/NullDev/Advent-of-Code/blob/master/2024/Day_19/part_1.js) and [Day_19/part_2.js](https://github.com/NullDev/Advent-of-Code/blob/master/2024/Day_19/part_2.js)
- One-Liner in [Day_23/part_1.js](https://github.com/NullDev/Advent-of-Code/blob/master/2024/Day_23/part_1.js)
- Single-Line [Bron–Kerbosch algorithm](https://en.wikipedia.org/wiki/Bron%E2%80%93Kerbosch_algorithm) in [Day_23/part_2.js](https://github.com/NullDev/Advent-of-Code/blob/master/2024/Day_23/part_2.js)

<hr>

Expand Down

0 comments on commit 488a855

Please sign in to comment.