Skip to content

Commit

Permalink
Solve 2024 day 3 part 2
Browse files Browse the repository at this point in the history
jeffs committed Dec 3, 2024
1 parent a4f6b5c commit 0e8c650
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions 2024/day3/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod part1;
pub mod part2;
3 changes: 2 additions & 1 deletion 2024/day3/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use day3::part1;
use day3::{part1, part2};

fn main() {
let input = include_str!("input");
println!("{}", part1::solve(input));
println!("{}", part2::solve(input));
}
22 changes: 22 additions & 0 deletions 2024/day3/src/part2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use crate::part1;

pub fn solve(input: &str) -> u32 {
input
.split("do()")
.map(|part| &part[..part.find("don't()").unwrap_or(part.len())])
.map(part1::solve)
.sum()
}

#[cfg(test)]
mod tests {
use super::*;

const SAMPLE: &str =
"xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))";

#[test]
fn test_solve() {
assert_eq!(solve(SAMPLE), 48);
}
}

0 comments on commit 0e8c650

Please sign in to comment.