1
0
mirror of https://gitlab.com/MisterBiggs/aoc2021.git synced 2025-08-03 03:41:25 +00:00
This commit is contained in:
2021-12-01 22:51:03 -07:00
parent 6b57a0330a
commit 3f4182acf4
7 changed files with 1111 additions and 0 deletions

36
day2/src/main.rs Normal file
View File

@@ -0,0 +1,36 @@
use std::fs;
fn main() {
let input = fs::read_to_string("./input.txt").expect("Could not read file");
let commands: Vec<(&str, i32)> = input
.lines()
.map(|s| {
let mut split = s.split_whitespace();
(
split.next().unwrap(),
split.next().unwrap().parse::<i32>().unwrap(),
)
})
.collect();
part1(commands)
}
fn part1(commands: Vec<(&str, i32)>) {
let mut position = 0;
let mut depth = 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),
};
position += change.0;
depth += change.1;
}
println!("Part 1: {}", position * depth);
}