Disclaimer for day23.2 solution
This commit is contained in:
13
src/day23.rs
13
src/day23.rs
@@ -76,18 +76,21 @@ fn part2(input: &str) -> String {
|
|||||||
.map(|(k, _)| k)
|
.map(|(k, _)| k)
|
||||||
.collect_vec();
|
.collect_vec();
|
||||||
|
|
||||||
if nodes.len() < k as usize {
|
if nodes.len() < (k + 1) as usize {
|
||||||
k -= 1;
|
k -= 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// now we find all nodes in the neighborhood of a (including a) that have an edge to every node in `nodes`, excluding themselves ofc
|
// now we check if indeed all of the candidate nodes are connected
|
||||||
let found = graph[a]
|
let found = nodes
|
||||||
.iter()
|
.iter()
|
||||||
.chain([*a].iter())
|
.filter(|&x| nodes.iter().all(|y| y == x || graph[*x].contains(*y)))
|
||||||
.filter(|x| nodes.iter().all(|y| y == x || graph[*x].contains(*y)))
|
|
||||||
.sorted_unstable()
|
.sorted_unstable()
|
||||||
.join(",");
|
.join(",");
|
||||||
|
// disclaimer: this works for this input but not in general (think of a graph where a is in the middle and the other nodes in
|
||||||
|
// a circle around it, each connected to their left and right neighbour. There could be 10 nodes with degree 3 in there
|
||||||
|
// but ofc they wouldn't be all connected - so this "solution" would return nothing, althoug a max clique of
|
||||||
|
// size 3 would exist)
|
||||||
|
|
||||||
if found.len() > best.len() {
|
if found.len() > best.len() {
|
||||||
best = found;
|
best = found;
|
||||||
|
|||||||
Reference in New Issue
Block a user