diff --git a/day8/src/main.rs b/day8/src/main.rs index 8346143..bd4b56e 100644 --- a/day8/src/main.rs +++ b/day8/src/main.rs @@ -28,11 +28,10 @@ fn main() { let mut lines_iter = lines_str.lines(); let directions = lines_iter.next().unwrap(); lines_iter.next(); - let mut nodes: HashMap<&str, (&str, &str)> = HashMap::new(); - for line in lines_iter { + let nodes = lines_iter.map(|line| { let mut ids = line.split([' ', '(', ')', '=', ',']).filter(|&str| !str.is_empty()); - nodes.insert(ids.next().unwrap(), (ids.next().unwrap(), ids.next().unwrap())); - } + (ids.next().unwrap(), (ids.next().unwrap(), ids.next().unwrap())) + }).collect::>(); let counter1 = get_steps_to(directions, &nodes, "AAA", |str| str == "ZZZ"); let counter2 = nodes.iter() .filter_map(|(&id, _)|