Skip to content

Instantly share code, notes, and snippets.

@jsancio
Created April 6, 2014 08:19
Show Gist options
  • Save jsancio/10003016 to your computer and use it in GitHub Desktop.
Save jsancio/10003016 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 {
match hours.find_mut(&hour) {
Some(names) => { names.push(name); },
None => { 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