···
collections::{HashMap, HashSet},
7
-
let input = include_str!("../../input_example.txt").trim();
7
+
let input = include_str!("../../input.txt").trim();
9
-
let mut input: Vec<&str> = input.trim().split("\n").collect();
10
-
let start = input[0].find("S").unwrap() as u32;
11
-
let splitters_map: Vec<HashSet<u32>> = input[0..input.len()]
9
+
let input: Vec<&str> = input.trim().split("\n").collect();
10
+
// let width = input[0].len() as u64;
11
+
let start = input[0].find("S").unwrap() as u64;
12
+
let splitters_map: Vec<HashSet<u64>> = input[0..input.len()]
.map(|(i, line)| if i % 2 != 0 { "" } else { line })
···
.fold(HashSet::new(), |mut s, (i, char)| {
···
29
-
let mut timelines: HashMap<String, u32> = HashMap::new();
30
-
timelines.insert("".to_string(), start);
30
+
let mut timelines: HashMap<u64, u64> = HashMap::new();
31
+
timelines.insert(start, 1);
32
+
let mut timelines_new: HashMap<u64, u64> = HashMap::new();
for splitters in splitters_map {
32
-
for (timeline, pos) in timelines.clone() {
34
+
for (pos, amount) in &timelines {
if splitters.contains(&pos) {
34
-
timelines.remove(&timeline);
35
-
timelines.insert(format!("{timeline}+"), pos + 1);
36
-
timelines.insert(format!("{timeline}-"), pos - 1);
36
+
let m1 = timelines_new.entry(pos - 1).or_insert(0);
38
+
let p1 = timelines_new.entry(pos + 1).or_insert(0);
41
+
let e = timelines_new.entry(*pos).or_insert(0);
45
+
// for pos in 0..width as u64 {
46
+
// if splitters.contains(&pos) {
48
+
// } else if timelines_new.contains_key(&pos) {
55
+
swap(&mut timelines, &mut timelines_new);
56
+
timelines_new.clear();
42
-
println!("{}", timelines.len());
60
+
// println!("{:?}", timelines);
61
+
println!("{}", timelines.iter().fold(0, |acc, v| { acc + v.1 }))