mirror of
https://gitlab.com/MisterBiggs/aoc2021.git
synced 2025-06-16 06:56:48 +00:00
pt 2
This commit is contained in:
parent
3f4182acf4
commit
ece33d6fd3
26
.gitignore
vendored
26
.gitignore
vendored
@ -1,14 +1,14 @@
|
|||||||
# Generated by Cargo
|
# Generated by Cargo
|
||||||
# will have compiled files and executables
|
# will have compiled files and executables
|
||||||
debug/
|
debug/
|
||||||
target/
|
target/
|
||||||
|
|
||||||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
|
|
||||||
# These are backup files generated by rustfmt
|
# These are backup files generated by rustfmt
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
|
|
||||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
*.pdb
|
*.pdb
|
@ -14,10 +14,11 @@ fn main() {
|
|||||||
})
|
})
|
||||||
.collect();
|
.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 position = 0;
|
||||||
let mut depth = 0;
|
let mut depth = 0;
|
||||||
|
|
||||||
@ -34,3 +35,23 @@ fn part1(commands: Vec<(&str, i32)>) {
|
|||||||
}
|
}
|
||||||
println!("Part 1: {}", position * depth);
|
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);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user