Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
shahata committed Dec 23, 2024
1 parent bac7302 commit ad07b65
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/2024/day23.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ function unique(networks) {
}

function addOneToNetworks(networks, map) {
networks = networks.flatMap(computers => {
let result = networks.flatMap(computers => {
let candidates = computers.map(c => map.get(c));
let result = [...candidates.reduce((a, b) => a.intersection(b))];
return result.map(x => [...computers, x]);
let additions = candidates.reduce((a, b) => a.intersection(b));
return [...additions].map(add => [...computers, add]);
});
return unique(networks);
return unique(result);
}

function parse(input) {
Expand Down

0 comments on commit ad07b65

Please sign in to comment.