Created
December 11, 2016 16:39
-
-
Save anonymous/0f4632e1a57943f6c2303c79baf51ba2 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug)] | |
struct Floor { | |
micros : std::collections::HashSet<char>, | |
gens : std::collections::HashSet<char>, | |
} | |
fn parsefloor(room: &str) -> Floor { | |
let mut floor = Floor{ | |
micros: std::collections::HashSet::<char>::new(), | |
gens: std::collections::HashSet::<char>::new()}; | |
let mut items = room.split(" a "); | |
items.next(); // throw away the preamble | |
for item in items { | |
let element = item.chars().next().unwrap(); | |
let shape = item.split(" ").nth(1).unwrap().chars().next().unwrap(); | |
match shape { | |
'm' => { | |
floor.micros.insert(element); | |
}, | |
'g' => { | |
floor.gens.insert(element); | |
}, | |
_ => { | |
println!("{:?}", floor); | |
} | |
}; | |
} | |
return floor | |
} | |
fn main () { | |
// sneaky empty 0th floor | |
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 floorstrings = input.split("\n"); | |
let mut floors : Vec<Floor> = vec![]; | |
for floorstring in floorstrings { | |
floors.push(parsefloor(floorstring)); | |
}; | |
for floor in floors.into_iter().rev() { | |
//floor.micros.insert('b'); | |
println!("{:?}", floor) | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment