adventofcode/days/2023/01.rs

34 Zeilen
1 KiB
Rust

use advent_of_code::include_aoc;
2024-12-08 01:44:21 +01:00
use advent_of_code::strings::{convert_to_array, get_numbers, get_string_numbers};
include_aoc!(DATAa, 2023, 01a);
include_aoc!(DATAb, 2023, 01b);
fn main() {
let mut sum: u32 = 0;
2024-12-08 01:44:21 +01:00
for coordinates in convert_to_array::<_, _, '\n'>(DATAa, get_numbers::<u32>) {
if coordinates.len() == 0 {
continue;
}
let first = coordinates.first().unwrap() * 10;
let last = *coordinates.last().unwrap();
let number = first + last;
println!("Number: {}", number);
sum += number;
}
println!("Sum of Numbers {}", sum);
sum = 0;
for coordinates in DATAb.split('\n').map(get_string_numbers) {
if coordinates.len() == 0 {
continue;
}
let first = coordinates.first().unwrap() * 10;
let last = *coordinates.last().unwrap();
let number = first + last;
println!("Number: {}", number);
sum += number;
}
println!("Sum of Numbers with strings {}", sum);
}