Skip to content

Commit

Permalink
Complete d16.2
Browse files Browse the repository at this point in the history
  • Loading branch information
d2weber committed Apr 13, 2023
1 parent ae73f5f commit 2688d7d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ harness = false

[dependencies]
either = "1.8.1"
itertools = "0.10.5"

[dev-dependencies]
criterion = "0.4.0"
34 changes: 28 additions & 6 deletions src/d16/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use itertools::Itertools;
use std::{
collections::HashMap,
fmt::Debug,
Expand Down Expand Up @@ -244,15 +245,36 @@ pub mod part2 {

pub fn solution(s: &str) -> u32 {
let valves = parse(s);
// valves
todo!()
let unvisited: Vec<Id> = valves
.clone()
.into_iter()
.map(|(k, _)| k)
.filter(|k| *k != START_ID)
.collect();
let mut max = 0;
let ceil_half = (unvisited.len() + 1) / 2;
for n_elephant in 0..=ceil_half {
unvisited
.clone()
.into_iter()
.combinations(n_elephant)
.for_each(|x| {
let mut my_unvisited = unvisited.clone();
my_unvisited.retain(|k| !x.contains(k));
let my_max = start_iteration(&valves, my_unvisited, 26);
let eleph_max = start_iteration(&valves, x, 26);
max = std::cmp::max(my_max + eleph_max, max);
})
}
max
}
#[test]
fn sample() {
assert_eq!(solution(SAMPLE), 1707);
}
// #[test]
// fn actual() {
// assert_eq!(solution(INPUT), 0);
// }
#[test]
#[ignore = "slow"]
fn actual() {
assert_eq!(solution(INPUT), 2520);
}
}

0 comments on commit 2688d7d

Please sign in to comment.