diff --git a/2016/rust/src/day_11.rs b/2016/rust/src/day_11.rs index 83fd274..4646a72 100644 --- a/2016/rust/src/day_11.rs +++ b/2016/rust/src/day_11.rs @@ -11,6 +11,7 @@ struct Facility { floors: Vec, } +#[derive(Debug, PartialEq)] struct Floor { items: Vec, } @@ -46,7 +47,7 @@ fn test_generators_and_microchips() { assert_eq!(floor.microchips(), vec!["b".to_string()]); } -#[derive(Clone, PartialEq)] +#[derive(Clone, Debug, PartialEq)] enum Item { Generator(String), Microchip(String), @@ -142,6 +143,28 @@ fn test_is_safe() { // The fourth floor contains nothing relevant. // As a diagram (F# for a Floor number, E for Elevator, H for Hydrogen, L for Lithium, M for Microchip, and G for Generator), the initial state looks like this: +impl str::FromStr for Facility { + type Err = Error; + + fn from_str(input: &str) -> Result { + let floors = input.lines() + .map(|line| line.parse::()) + .collect::>>()?; + Ok(Facility{floors}) + } +} + +#[test] +fn test_facility_from_str() { + let input = "The first floor contains a hydrogen-compatible microchip and a lithium-compatible microchip. +The second floor contains a hydrogen generator. +The third floor contains a lithium generator. +The fourth floor contains nothing relevant."; + let facility: Facility = input.parse().unwrap(); + assert_eq!(facility.floors.len(), 4); + assert_eq!(facility.floors[1], Floor{items: vec![Item::Generator("hydrogen".into())]}); +} + impl str::FromStr for Floor { type Err = Error; @@ -247,3 +270,15 @@ fn test_floor_from_str() { // In this arrangement, it takes 11 steps to collect all of the objects at the fourth floor for assembly. (Each elevator stop counts as one step, even if nothing is added to or removed from it.) // // In your situation, what is the minimum number of steps required to bring all of the objects to the fourth floor? + +pub fn solve(input: &str) -> Result { + return Ok("".into()) +} + +#[test] +fn test_solve() { + let input = "The first floor contains a hydrogen-compatible microchip and a lithium-compatible microchip. +The second floor contains a hydrogen generator. +The third floor contains a lithium generator. +The fourth floor contains nothing relevant."; +} diff --git a/2016/rust/src/main.rs b/2016/rust/src/main.rs index 8eba962..a58c0ba 100644 --- a/2016/rust/src/main.rs +++ b/2016/rust/src/main.rs @@ -10,7 +10,7 @@ fn main() { let mut input = String::new(); io::stdin().read_to_string(&mut input).ok(); - let solution = day_23::solve(&input)?; + let solution = day_11::solve(&input)?; println!("{}", solution); Ok(())