Compare commits

..

No commits in common. "237ca363812f8b870d8a243e07030a9920462d24" and "d3ce12693bc84006160c007d9c75da729e49e49b" have entirely different histories.

3 changed files with 7 additions and 50 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 7.5 KiB

View File

@ -1,6 +1,6 @@
<!-- AOC TILES BEGIN -->
<h1 align="center">
2024 - 45 ⭐ - Rust
2024 - 44 ⭐ - Rust
</h1>
<a href="src/day1.rs">
<img src=".aoc_tiles/tiles/2024/01.png" width="161px">

View File

@ -1,7 +1,8 @@
use std::fmt::Debug;
use aoc_runner_derive::aoc;
use itertools::Itertools;
use rustc_hash::{FxHashMap, FxHashSet};
use std::fmt::{Debug, Display};
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
struct Node([char; 2]);
@ -12,12 +13,6 @@ impl Debug for Node {
}
}
impl Display for Node {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!("{}", self.0.iter().join("")))
}
}
impl From<[char; 2]> for Node {
fn from(value: [char; 2]) -> Self {
Node(value)
@ -56,38 +51,6 @@ impl Network {
}
sets
}
fn bron_kerbosch(
&self,
r: FxHashSet<Node>,
mut p: FxHashSet<Node>,
mut x: FxHashSet<Node>,
) -> Vec<FxHashSet<Node>> {
let mut results = Vec::new();
if p.is_empty() && x.is_empty() {
return vec![r];
}
let p_iter = p.clone(); // so we can modify p
for node in &p_iter {
let mut new_r = r.clone();
new_r.insert(*node);
let neighbours = FxHashSet::from_iter(self.edges.get(node).unwrap().iter().copied());
let new_p = FxHashSet::from_iter(p.intersection(&neighbours).copied());
let new_x = FxHashSet::from_iter(x.intersection(&neighbours).copied());
results.extend(self.bron_kerbosch(new_r, new_p, new_x).into_iter());
p.remove(node);
x.insert(*node);
}
results
}
fn maximal_subgraphs(&self) -> Vec<FxHashSet<Node>> {
self.bron_kerbosch(
FxHashSet::default(),
FxHashSet::from_iter(self.nodes.iter().copied()),
FxHashSet::default(),
)
}
}
impl From<&str> for Network {
@ -120,23 +83,17 @@ fn parse(input: &str) -> Network {
#[aoc(day23, part1)]
pub fn part1(input: &str) -> i64 {
let network = parse(input);
// println!("edges: {:?}", network.edges);
println!("edges: {:?}", network.edges);
let sets = network.groups_3();
let t_count = sets.iter().filter(|set| set.iter().any(|s| s.0[0] == 't')).count();
// println!("groups: {:?}", sets);
println!("groups: {:?}", sets);
t_count as i64
}
#[aoc(day23, part2)]
pub fn part2(input: &str) -> String {
let network = parse(input);
let best_sets = network.maximal_subgraphs();
let largest_set = best_sets.iter().max_by(|a, b| a.len().cmp(&b.len())).unwrap();
let mut largest = largest_set.iter().collect_vec();
largest.sort();
println!("best: {:?}", largest);
largest.iter().join(",")
todo!()
}
#[cfg(test)]