// Santa was hoping for a white Christmas, but his weather machine's "snow" function is powered by // stars, and he's fresh out! To save Christmas, he needs you to collect fifty stars by December // 25th. // // Santa is trying to deliver presents in a large apartment building, but he can't find the right // floor - the directions he got are a little confusing. He starts on the ground floor (floor 0) // and then follows the instructions one character at a time. // // An opening parenthesis, (, means he should go up one floor, and a closing parenthesis, ), means // he should go down one floor. // // The apartment building is very tall, and the basement is very deep; he will never find the top // or bottom floors. // // For example: // // (()) and ()() both result in floor 0. // ((( and (()(()( both result in floor 3. // ))((((( also results in floor 3. // ()) and ))( both result in floor -1 (the first basement level). // ))) and )())()) both result in floor -3. // To what floor do the instructions take Santa? // use aoc::read_data; fn main() { let instructions = read_data("2015_01_data.txt"); let mut current_floor = 0; for next_direction in instructions.chars() { match next_direction { ')' => current_floor -= 1, '(' => current_floor += 1, _ => { panic!("Invalid Direction. Santa got lost."); } } } println!("Ending on floor {}", current_floor); } // 232