problem01
This commit is contained in:
parent
0bc11cef68
commit
2d4290f643
|
@ -1,7 +1,7 @@
|
||||||
use tAoC2022::problem01;
|
use tAoC2022::problem01;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
println!("== Problem 01 ==");
|
||||||
problem01::solutionA();
|
println!("{}", problem01::solutionA());
|
||||||
problem01::solutionB();
|
println!("{}", problem01::solutionB());
|
||||||
}
|
}
|
||||||
|
|
2250
src/problem01/input.txt
Normal file
2250
src/problem01/input.txt
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,7 +1,36 @@
|
||||||
pub fn solutionA() {
|
static INPUT: &'static str = include_str!("input.txt");
|
||||||
println!("this will eventually be a problem solution");
|
|
||||||
|
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() {
|
fn add_to_total(totals: &mut Vec<i32>, total: i32) {
|
||||||
println!("this will eventually be a problem solution... B");
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue