advent_of_code/year2015/
day01.rs1use crate::input::Input;
2
3pub fn solve(input: &Input) -> Result<i32, String> {
4 let mut floor = 0;
5 for (idx, c) in input.text.chars().enumerate() {
6 floor += match c {
7 '(' => 1,
8 ')' => -1,
9 _ => {
10 return Err(format!("Invalid char at offset {idx}: '{c}'"));
11 }
12 };
13 if input.is_part_two() && floor == -1 {
14 return Ok(idx as i32 + 1);
15 }
16 }
17 Ok(floor)
18}
19
20#[test]
21pub fn tests() {
22 let real_input = include_str!("day01_input.txt");
23 test_part_one!(real_input => 280);
24 test_part_two!(real_input => 1797);
25}