Added 1 and 2

This commit is contained in:
2021-12-03 15:17:28 +01:00
parent 069a30205f
commit 641a176c77
12 changed files with 6161 additions and 0 deletions

8
december_2_2/Cargo.toml Normal file
View File

@@ -0,0 +1,8 @@
[package]
name = "december_2_2"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

1000
december_2_2/input.txt Normal file

File diff suppressed because it is too large Load Diff

39
december_2_2/src/main.rs Normal file
View File

@@ -0,0 +1,39 @@
use std::fs::File;
use std::io::{BufReader};
use std::io::prelude::*;
fn main(){
let file = File::open("./input.txt").expect("Read failed");
let reader = BufReader::new(file);
let mut current_depth = 0;
let mut current_horizontal = 0;
let mut aim = 0;
let all_lines = reader.lines();
for line in all_lines{
let line_as_string = line.unwrap();
let split_line = line_as_string.split_whitespace().collect::<Vec<&str>>();
let direction = split_line[0];
let distance = split_line[1].parse::<i32>().unwrap();
match direction {
"down" => aim += distance,
"up" => aim -= distance,
"forward" => {
current_horizontal += distance;
current_depth += aim * distance;
}
_ => println!("You should never be here")
}
}
println!("Depth: {}, Horizontal: {}, Result: {}", current_depth, current_horizontal, current_horizontal*current_depth)
}