|
|
|
@ -4,17 +4,16 @@ use std::str::Chars;
|
|
|
|
|
use day::Day;
|
|
|
|
|
|
|
|
|
|
pub struct Day01 {
|
|
|
|
|
input: String,
|
|
|
|
|
elevator: Elevator,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Day for Day01 {
|
|
|
|
|
fn new(input: String) -> Day01 {
|
|
|
|
|
Day01 { input: input }
|
|
|
|
|
Day01 { elevator: Elevator::new(input) }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn solve(&self) -> io::Result<i32> {
|
|
|
|
|
let elevator = Elevator::new(&self.input);
|
|
|
|
|
Ok(1 + elevator.run().position(|f| f == -1).unwrap_or(0) as i32)
|
|
|
|
|
Ok(1 + self.elevator.run().position(|f| f == -1).unwrap_or(0) as i32)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -23,8 +22,8 @@ struct Elevator {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a> Elevator {
|
|
|
|
|
fn new(input: &String) -> Self {
|
|
|
|
|
Elevator { instructions: input.clone() }
|
|
|
|
|
fn new(input: String) -> Self {
|
|
|
|
|
Elevator { instructions: input }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn run(self: &'a Self) -> ElevatorIterator<'a> {
|
|
|
|
|