From b987f56e5dccc1d1753fa3f54fa4851b04ac43e1 Mon Sep 17 00:00:00 2001 From: Johannes Date: Sun, 8 Dec 2024 18:12:12 +0100 Subject: [PATCH] fixed day 7 concat operator where rhs is 10^x --- src/day07.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/day07.rs b/src/day07.rs index 24852df..8bf9356 100644 --- a/src/day07.rs +++ b/src/day07.rs @@ -98,7 +98,7 @@ fn well(expected: i64, acc: i64, operands: &[i64]) -> bool { } fn concat(lhs: i64, rhs: i64) -> i64 { - let exp: u32 = (rhs as f64).log10().ceil() as u32; + let exp: u32 = (rhs as f64 + 1.0).log10().ceil() as u32; let shift = 10i64.pow(exp); lhs * shift + rhs } @@ -130,5 +130,6 @@ mod test { #[test] fn test_concat() { assert_eq!(1234, concat(12, 34)); + assert_eq!(1210, concat(12, 10)); } }