Added 1 and 2
This commit is contained in:
8
december_2_1/Cargo.toml
Normal file
8
december_2_1/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "december_2_1"
|
||||
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_1/input.txt
Normal file
1000
december_2_1/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
35
december_2_1/src/main.rs
Normal file
35
december_2_1/src/main.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
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 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 {
|
||||
"forward" => current_horizontal += distance,
|
||||
"down" => current_depth += distance,
|
||||
"up" => current_depth -= distance,
|
||||
_ => println!("You should never be here")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
println!("Depth: {}, Horizontal: {}, Result: {}", current_depth, current_horizontal, current_horizontal*current_depth)
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user