adventofcode/days/2023/01.rs

34 Zeilen
1 KiB
Rust

use advent_of_code::strings::{convert_to_array, get_numbers, get_string_numbers};
#[allow(unused_imports)]
use advent_of_code::{include_data, include_example};
include_data!(DATAa 2023 01a);
include_data!(DATAb 2023 01b);
fn main() {
let mut sum: u32 = 0;
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);
}