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