Started on aoc 2015, finished day 1
This commit is contained in:
8
advent_of_code/2015/1/Cargo.toml
Normal file
8
advent_of_code/2015/1/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "main"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
1
advent_of_code/2015/1/input.txt
Normal file
1
advent_of_code/2015/1/input.txt
Normal file
File diff suppressed because one or more lines are too long
32
advent_of_code/2015/1/src/main.rs
Normal file
32
advent_of_code/2015/1/src/main.rs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
fn main() {
|
||||||
|
println!("Hello, this is Patrick!");
|
||||||
|
|
||||||
|
let input_txt = include_str!("../input.txt");
|
||||||
|
|
||||||
|
let mut floor = 0;
|
||||||
|
|
||||||
|
for parenthesis in input_txt.chars() {
|
||||||
|
match parenthesis {
|
||||||
|
'(' => floor += 1,
|
||||||
|
')' => floor -= 1,
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Santa needs to go to floor {}", floor);
|
||||||
|
|
||||||
|
let input_txt = include_str!("../input.txt");
|
||||||
|
let mut floor = 0;
|
||||||
|
|
||||||
|
for (idx, parenthesis) in input_txt.chars().enumerate() {
|
||||||
|
match parenthesis {
|
||||||
|
'(' => floor += 1,
|
||||||
|
')' => floor -= 1,
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
if floor == -1 {
|
||||||
|
println!("Santa first reaches the basement at position {}", idx + 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user