+12
-6
2025/7/rust/src/main.rs
+12
-6
2025/7/rust/src/main.rs
···
1
1
use std::{
2
2
char,
3
3
collections::{HashMap, HashSet},
4
+
mem::swap,
4
5
};
5
6
6
7
fn main() {
7
-
let input = include_str!("../../input_example.txt").trim();
8
+
let input = include_str!("../../input.txt").trim();
8
9
9
10
let mut input: Vec<&str> = input.trim().split("\n").collect();
10
11
let start = input[0].find("S").unwrap() as u32;
···
28
29
let timelines = {
29
30
let mut timelines: HashMap<String, u32> = HashMap::new();
30
31
timelines.insert("".to_string(), start);
31
-
for splitters in splitters_map {
32
-
for (timeline, pos) in timelines.clone() {
32
+
let mut timelines_new: HashMap<String, u32> = HashMap::new();
33
+
for (i, splitters) in splitters_map.iter().enumerate() {
34
+
println!("at: {}", i);
35
+
for (timeline, pos) in &timelines {
33
36
if splitters.contains(&pos) {
34
-
timelines.remove(&timeline);
35
-
timelines.insert(format!("{timeline}+"), pos + 1);
36
-
timelines.insert(format!("{timeline}-"), pos - 1);
37
+
timelines_new.insert(format!("{timeline}+"), pos + 1);
38
+
timelines_new.insert(format!("{timeline}-"), pos - 1);
39
+
} else {
40
+
timelines_new.insert(format!("{timeline}|"), *pos);
37
41
}
38
42
}
43
+
swap(&mut timelines, &mut timelines_new);
44
+
timelines_new.clear();
39
45
}
40
46
timelines
41
47
};