Skip to content

Instantly share code, notes, and snippets.

@huonw
Forked from jsancio/main.rs
Last active August 29, 2015 13:58
Show Gist options
  • Save huonw/10003049 to your computer and use it in GitHub Desktop.
Save huonw/10003049 to your computer and use it in GitHub Desktop.
extern crate collections;
use collections::TrieMap;
fn main() {
let workers = vec!(
("Jack", vec!((0000, 200), (500, 1200))),
("Jackie", vec!((0000, 600), (800, 1300))),
("Marty", vec!((400, 600), (1100, 1600), (1700, 2359))),
("Ronald", vec!((600, 1200), (1300, 1800), (1900, 2359))),
("Ke$ha", vec!((1600, 2359))),
("Tim", vec!((500, 1200), (1530, 1900), (2000, 2300))),
("Snoo", vec!((700, 900))));
let mut hours: TrieMap<Vec<&'static str>> = TrieMap::new();
for (name, available) in workers.move_iter() {
for (start, end) in available.move_iter() {
let mut hour = start;
while hour < end {
let should_insert = match hours.find_mut(&hour) {
Some(names) => { names.push(name); false }
None => true
};
if should_insert {
hours.insert(hour, vec!(name));
}
hour += 100;
}
}
}
for (key, workers) in hours.iter() {
println!("{} = {}", key, workers);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment