more fuctional

This commit is contained in:
Acvaxoort 2023-12-08 14:26:37 +01:00
parent d2db596bae
commit 9091376a90

View File

@ -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::<HashMap<_, _>>();
let counter1 = get_steps_to(directions, &nodes, "AAA", |str| str == "ZZZ");
let counter2 = nodes.iter()
.filter_map(|(&id, _)|