···
collections::{HashMap, HashSet},
-
let input = include_str!("../../input_example.txt").trim();
let mut input: Vec<&str> = input.trim().split("\n").collect();
let start = input[0].find("S").unwrap() as u32;
···
let mut timelines: HashMap<String, u32> = HashMap::new();
timelines.insert("".to_string(), start);
-
for splitters in splitters_map {
-
for (timeline, pos) in timelines.clone() {
if splitters.contains(&pos) {
-
timelines.remove(&timeline);
-
timelines.insert(format!("{timeline}+"), pos + 1);
-
timelines.insert(format!("{timeline}-"), pos - 1);
···
collections::{HashMap, HashSet},
+
let input = include_str!("../../input.txt").trim();
let mut input: Vec<&str> = input.trim().split("\n").collect();
let start = input[0].find("S").unwrap() as u32;
···
let mut timelines: HashMap<String, u32> = HashMap::new();
timelines.insert("".to_string(), start);
+
let mut timelines_new: HashMap<String, u32> = HashMap::new();
+
for (i, splitters) in splitters_map.iter().enumerate() {
+
for (timeline, pos) in &timelines {
if splitters.contains(&pos) {
+
timelines_new.insert(format!("{timeline}+"), pos + 1);
+
timelines_new.insert(format!("{timeline}-"), pos - 1);
+
timelines_new.insert(format!("{timeline}|"), *pos);
+
swap(&mut timelines, &mut timelines_new);