problem01

This commit is contained in:
Thorn Avery 2022-12-01 18:55:57 +11:00
parent 0bc11cef68
commit 2d4290f643
3 changed files with 2286 additions and 7 deletions

View file

@ -1,7 +1,7 @@
use tAoC2022::problem01;
fn main() {
println!("Hello, world!");
problem01::solutionA();
problem01::solutionB();
println!("== Problem 01 ==");
println!("{}", problem01::solutionA());
println!("{}", problem01::solutionB());
}

2250
src/problem01/input.txt Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,36 @@
pub fn solutionA() {
println!("this will eventually be a problem solution");
static INPUT: &'static str = include_str!("input.txt");
fn solution(x: i32) -> i32 {
let mut totals = vec![Default::default(); x.try_into().unwrap()];
let mut total = 0;
for line in INPUT.lines() {
if line == "" {
add_to_total(&mut totals, total);
total = 0;
} else {
let n: i32 = line.trim().parse().expect("invalid input");
total += n;
};
};
return totals.iter().sum();
}
pub fn solutionB() {
println!("this will eventually be a problem solution... B");
fn add_to_total(totals: &mut Vec<i32>, total: i32) {
let mut i = total;
for n in totals.iter_mut() {
if i > *n {
let tmp = *n;
*n = i;
i = tmp;
};
};
}
pub fn solutionA() -> i32 {
return solution(1);
}
pub fn solutionB() -> i32 {
return solution(3);
}