From 5a820ea842ea96ee24fe31238f26b1546fa9b407 Mon Sep 17 00:00:00 2001 From: bOli Date: Sat, 7 Dec 2024 08:05:20 +0100 Subject: [PATCH] Solved AOC 2024 day 7 --- 2024/input/day07.txt | Bin 0 -> 24490 bytes 2024/src/day07.rs | 119 +++++++++++++++++++++++++++++++++++++++++++ 2024/src/main.rs | 2 + 3 files changed, 121 insertions(+) create mode 100644 2024/input/day07.txt create mode 100644 2024/src/day07.rs diff --git a/2024/input/day07.txt b/2024/input/day07.txt new file mode 100644 index 0000000000000000000000000000000000000000..97c0e20ea470aa8969937f63f6e946cf2cfb528a GIT binary patch literal 24490 zcmV(rK<>W)M@dveQdv+`09ZtR6K8rYpHE|dDb8HXjr}jZz+He((b6z+B3Uv8?@ZbT zr!7myWWP6R@J6MQySXClw9|q{u0)pV&D}RnX;VW$6f_MtNOF&cZ-Q8~aZ#+~Xzq6U zrt3&wu70OOb4SadFF&_nG)mLj^am01*IOp}+f)hxbr&&(j|N?6@$&`) z@vdVt!&+B%9K-go7uX9STcdiiErY~a98ze?MV@1tIt6sq%BFq98$!=MemkNvM&&%j z`v#`%@GlCWE_vwD0kkv@lA0>&uK z&~siN)|Wu5Kk44(d$a6Yr!k&!HsGv77(_ItS-)5v%k z`a*Q4R_=*Xu{xTMRRaGiIphq-AvPm;GkvYF5wJPC?QK%*=49V;1T;8xiefj8UD|FI z8|fl**11M&=#*aPlE!5f=JER0JHX!XVSt6d!b*LMU+L|6V0hSMVOsGMn{9at9vXUu z9W8W76BOYEVSY$_a4Y;Pv>XtK~U~U zoU)0o-4F#o1Sc-KKv-{<@+`>rdZ8)POK-qb1hkSKxA^4vrjM%hY8iG}O)0a2aX-M} z+yub>k7FV0+UWxEO}%|;^{g16lAXMLA#>`~#`jL*sG;zD7%)VksAKv)Un2}Ypd^|; z6QAD^r&y5}}2zq07vgH50wBaW#u7)Cd>2%d~c`Pl_%0RCi4B99YekXA0ol%C3@-#LCf{ zAg(>yDq#-Dam-*z6L;W=JRG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L1MXzV?sg#|?UlY9xhzrkzy@*iNs;+t`( zMFoNNV?|EO9`X2d;!koE@Mg#^;dr64$(Fg5>a5(6rBMM$4Kqgkhd3{!9}haXHU`Y~ z9cQ3Mh&Kx66fXV#OH3A7lP%N)z`A!nf__~90P_9IGS7zl3BH=~xq3NAx z+IXEY)vaj00jxj{@8vY4ofH&gh{8-5CT-D6{(%Lx_NmykGMqn@P(S_>hzG5y6Sh#A zjnK0r-E)tjAvC-sD7ThbOikHQb#9*c# zpd+FV{x2jJxjiP%kXW~^uFfxWHFUwvPj3!51smI{)^6!R`U$JU@V(@j{;RBnS?s!k zrU&Y<7^r@Q%-U;*(X5pjrV8Twit#_NXqW|xY*f-uZjA)mQc#NHMy`|{EpjPMSZ0xZ z%w?$gvrP{6>J#KNjEYYP0$f2;-OvqXJ4HUc3*$$EbJjWA%yDmz+n_40`)JI@{N0Wo NE=^C`v8@UiE4+`Gl~4cx literal 0 HcmV?d00001 diff --git a/2024/src/day07.rs b/2024/src/day07.rs new file mode 100644 index 0000000..292087b --- /dev/null +++ b/2024/src/day07.rs @@ -0,0 +1,119 @@ +const INPUT: &str = include_str!("../../2024/input/day07.txt"); + +pub(crate) fn part1() -> usize { + solve_part1(INPUT) +} + +pub(crate) fn part2() -> usize { + solve_part2(INPUT) +} + +fn solve_part1(input: &str) -> usize { + parse(input) + .filter(Equation::has_solution_without_concatenation) + .map(Equation::left_side) + .sum() +} + +fn solve_part2(input: &str) -> usize { + parse(input) + .filter(Equation::has_solution_with_concatenation) + .map(Equation::left_side) + .sum() +} + +#[derive(Debug)] +struct Equation { + left_side: usize, + right_side: Vec, +} +impl Equation { + fn left_side(self) -> usize { + self.left_side + } + fn has_solution_without_concatenation(&self) -> bool { + Equation::has_solution(self.left_side, &self.right_side, false) + } + fn has_solution_with_concatenation(&self) -> bool { + Equation::has_solution(self.left_side, &self.right_side, true) + } + fn has_solution(left_side: usize, right_side: &[usize], allow_concat: bool) -> bool { + let last_idx = right_side.len() - 1; + let last_num = right_side[last_idx]; + if right_side.len() == 1 { + return left_side == last_num; + } + let front_nums = &right_side[..last_idx]; + + let last_operation_is_addition = || { + left_side > last_num + && Equation::has_solution(left_side - last_num, front_nums, allow_concat) + }; + let last_op_is_multiplication = || { + left_side % last_num == 0 + && Equation::has_solution(left_side / last_num, front_nums, allow_concat) + }; + let last_op_is_concatenation = || { + let last_num_string = last_num.to_string(); + let concat_divisor = 10usize.pow(last_num_string.len() as u32); + left_side.to_string().ends_with(&last_num_string) + && Equation::has_solution(left_side / concat_divisor, front_nums, allow_concat) + }; + + last_operation_is_addition() + || last_op_is_multiplication() + || allow_concat && last_op_is_concatenation() + } +} + +fn parse(input: &str) -> impl Iterator + use<'_> { + input.trim().lines().map(|line| { + let (left, right) = line.split_once(": ").unwrap(); + let left = left.parse().unwrap(); + let right = right + .split_whitespace() + .map(|n| n.parse().unwrap()) + .collect(); + Equation { + left_side: left, + right_side: right, + } + }) +} + +#[cfg(test)] +mod tests { + use super::*; + + const EXAMPLE: &str = "\ +190: 10 19 +3267: 81 40 27 +83: 17 5 +156: 15 6 +7290: 6 8 6 15 +161011: 16 10 13 +192: 17 8 14 +21037: 9 7 18 13 +292: 11 6 16 20 +"; + + #[test] + fn test_part1_example() { + assert_eq!(190 + 3267 + 292, solve_part1(EXAMPLE)); + } + + #[test] + fn test_part1() { + assert_eq!(42_283_209_483_350, solve_part1(INPUT)); + } + + #[test] + fn test_part2_example() { + assert_eq!(190 + 3267 + 156 + 7290 + 192 + 292, solve_part2(EXAMPLE)); + } + + #[test] + fn test_part2() { + assert_eq!(1_026_766_857_276_279, solve_part2(INPUT)); + } +} diff --git a/2024/src/main.rs b/2024/src/main.rs index 488ae9f..96f4f4e 100644 --- a/2024/src/main.rs +++ b/2024/src/main.rs @@ -6,6 +6,7 @@ mod day03; mod day04; mod day05; mod day06; +mod day07; fn main() { print_result(1, day01::part1(), day01::part2()); @@ -14,6 +15,7 @@ fn main() { print_result(1, day04::part1(), day04::part2()); print_result(1, day05::part1(), day05::part2()); print_result(1, day06::part1(), day06::part2()); + print_result(1, day07::part1(), day07::part2()); } fn print_result(day: i32, part1: impl Display, part2: impl Display) {