Skip to content

Commit 5c75072

Browse files
committed
Day25: Initial solution
1 parent 12be7b9 commit 5c75072

File tree

6 files changed

+235
-6
lines changed

6 files changed

+235
-6
lines changed

Cargo.lock

Lines changed: 159 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ smallstr = "0.3.0"
2626
polyfit-rs = "0.2.1"
2727
petgraph = "0.7.1"
2828
nalgebra = "0.33.2"
29+
rustworkx-core = "0.15.1"
2930

3031
[profile.release]
3132
lto = "thin"

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@
4646
- [solution](src/day22.rs)
4747
- [Day 23: A Long Walk](https://adventofcode.com/2023/day/23)
4848
- [solution](src/day23.rs)
49-
- [Day 24:](https://adventofcode.com/2023/day/24)
49+
- [Day 24: Never Tell Me The Odds](https://adventofcode.com/2023/day/24)
5050
- [solution](src/day24.rs)
51+
- [Day 25: Snowverload](https://adventofcode.com/2023/day/25)
52+
- [solution](src/day25.rs)
5153
<!-- Insert before -->
5254

5355
See:

input

Submodule input updated from 87856af to b75b1f4

src/day25.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
use aoc_runner_derive::aoc;
2+
use rustworkx_core::{connectivity::stoer_wagner_min_cut, petgraph::prelude::UnGraphMap};
3+
4+
#[aoc(day25, part1)]
5+
pub fn part1(input: &str) -> usize {
6+
let graph = UnGraphMap::<_, ()>::from_edges(input.lines().flat_map(|line| {
7+
let key = &line[..3];
8+
line[5..].split(' ').map(move |node| (key, node))
9+
}));
10+
11+
let group = stoer_wagner_min_cut(&graph, |_| Ok::<_, ()>(1))
12+
.unwrap()
13+
.unwrap()
14+
.1;
15+
16+
let g1 = group.len();
17+
let g2 = graph.node_count() - g1;
18+
19+
g1 * g2
20+
}
21+
22+
#[cfg(test)]
23+
mod tests {
24+
use super::*;
25+
26+
const SAMPLE: &str = r"jqt: rhn xhk nvd
27+
rsh: frs pzl lsr
28+
xhk: hfx
29+
cmg: qnr nvd lhk bvb
30+
rhn: xhk bvb hfx
31+
bvb: xhk hfx
32+
pzl: lsr hfx nvd
33+
qnr: nvd
34+
ntq: jqt hfx bvb xhk
35+
nvd: lhk
36+
lsr: lhk
37+
rzs: qnr cmg lsr rsh
38+
frs: qnr lhk lsr";
39+
40+
#[test]
41+
pub fn input_test() {
42+
// println!("{:?}", generator(SAMPLE));
43+
44+
// assert_eq!(generator(SAMPLE), Object());
45+
}
46+
47+
#[test]
48+
pub fn part1_test() {
49+
assert_eq!(part1(SAMPLE), 54);
50+
}
51+
52+
#[test]
53+
pub fn part2_test() {
54+
// assert_eq!(part2(&generator(SAMPLE)), 336);
55+
}
56+
57+
mod regression {
58+
use super::*;
59+
60+
const INPUT: &str = include_str!("../input/2023/day25.txt");
61+
const ANSWERS: (usize, usize) = (552695, 0);
62+
63+
#[test]
64+
pub fn test() {
65+
let input = INPUT.trim_end_matches('\n');
66+
assert_eq!(part1(input), ANSWERS.0);
67+
// assert_eq!(part2(&output), ANSWERS.1);
68+
}
69+
}
70+
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ pub mod day21;
2525
pub mod day22;
2626
pub mod day23;
2727
pub mod day24;
28+
pub mod day25;
2829
// Insert before
2930
aoc_lib! { year = 2023 }

0 commit comments

Comments
 (0)