#[aoc(day3, part1)] pub fn part1(input: &str) -> u32 { input.split("\n").map(|line| get_joltage(line)).sum() } fn get_joltage(line: &str) -> u32 { let len = line.len(); let (revpos_1, val_1) = line[..(len - 1)] .chars() .rev() .enumerate() .max_by(|x, y| x.1.cmp(&y.1)) .unwrap(); let val_2 = line[(len - 1 - revpos_1)..].chars().max().unwrap(); let result = val_1.to_digit(10).unwrap() * 10 + val_2.to_digit(10).unwrap(); result } #[cfg(test)] mod tests { use super::*; #[test] fn test_part1_1() { let input = String::from( "987654321111111 811111111111119 234234234234278 818181911112111", ); assert_eq!(part1(&input), 357) } #[test] fn test_part1_2() { let input = String::from( "9891111111111111111 111111111111111 818181911112111", ); assert_eq!(part1(&input), 99 + 11 + 92) } }