1
0
mirror of https://gitlab.com/MisterBiggs/aoc2021.git synced 2025-06-16 06:56:48 +00:00
This commit is contained in:
Anson Biggs 2021-12-01 23:03:53 -07:00
parent 3f4182acf4
commit ece33d6fd3
2 changed files with 36 additions and 15 deletions

View File

@ -14,10 +14,11 @@ fn main() {
})
.collect();
part1(commands)
part1(&commands);
part2(&commands);
}
fn part1(commands: Vec<(&str, i32)>) {
fn part1(commands: &Vec<(&str, i32)>) {
let mut position = 0;
let mut depth = 0;
@ -34,3 +35,23 @@ fn part1(commands: Vec<(&str, i32)>) {
}
println!("Part 1: {}", position * depth);
}
fn part2(commands: &Vec<(&str, i32)>) {
let mut position = 0;
let mut depth = 0;
let mut aim = 0;
for (dir, amt) in commands.iter().map(|a| *a) {
let change = match dir {
"forward" => (amt, 0),
"up" => (0, -amt),
"down" => (0, amt),
_ => (0, 0),
};
aim += change.1;
position += change.0;
depth += aim * change.0;
}
println!("Part 2: {}", position * depth);
}