Started on aoc 2015, finished day 1
This commit is contained in:
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