advent-of-code-2024/day23/part2.rs

33 lines
912 B
Rust
Raw Normal View History

2024-12-22 22:04:30 -07:00
use std::collections::HashMap;
use itertools::Itertools as _;
const INPUT: &str = include_str!("input.txt");
fn main() {
// Assemble graph
let mut graph = HashMap::<&str, Vec<&str>>::new();
for line in INPUT.lines() {
let (first, second) = line.split_once('-').unwrap();
graph.entry(first).or_default().push(second);
graph.entry(second).or_default().push(first);
}
let mut maximum_clique = Vec::<&&str>::new();
for start_node in graph.keys() {
let mut clique = Vec::<&&str>::from([start_node]);
for node in graph.keys() {
if clique.iter().all(|n| graph[node].contains(n)) {
clique.push(node);
}
}
if clique.len() > maximum_clique.len() {
maximum_clique = clique;
}
}
maximum_clique.sort();
println!("Result: {}", maximum_clique.into_iter().join(","));
}