[rust] Day 1 simplification

wip
Alpha Chen 9 years ago
parent 3ebcf0fbeb
commit 184b4bb646

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

Loading…
Cancel
Save