my solutions to advent of code
aoc advent-of-code

Compare changes

Choose any two refs to compare.

Changed files
+32 -13
2025
7
rust
src
+32 -13
2025/7/rust/src/main.rs
···
use std::{
-
char,
collections::{HashMap, HashSet},
+
mem::swap,
};
fn main() {
-
let input = include_str!("../../input_example.txt").trim();
+
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 splitters_map: Vec<HashSet<u32>> = input[0..input.len()]
+
let input: Vec<&str> = input.trim().split("\n").collect();
+
// let width = input[0].len() as u64;
+
let start = input[0].find("S").unwrap() as u64;
+
let splitters_map: Vec<HashSet<u64>> = input[0..input.len()]
.iter()
.enumerate()
.map(|(i, line)| if i % 2 != 0 { "" } else { line })
···
.enumerate()
.fold(HashSet::new(), |mut s, (i, char)| {
if char == '^' {
-
s.insert(i as u32);
+
s.insert(i as u64);
}
s
})
···
.collect();
let timelines = {
-
let mut timelines: HashMap<String, u32> = HashMap::new();
-
timelines.insert("".to_string(), start);
+
let mut timelines: HashMap<u64, u64> = HashMap::new();
+
timelines.insert(start, 1);
+
let mut timelines_new: HashMap<u64, u64> = HashMap::new();
for splitters in splitters_map {
-
for (timeline, pos) in timelines.clone() {
+
for (pos, amount) in &timelines {
if splitters.contains(&pos) {
-
timelines.remove(&timeline);
-
timelines.insert(format!("{timeline}+"), pos + 1);
-
timelines.insert(format!("{timeline}-"), pos - 1);
+
let m1 = timelines_new.entry(pos - 1).or_insert(0);
+
*m1 += amount;
+
let p1 = timelines_new.entry(pos + 1).or_insert(0);
+
*p1 += amount;
+
} else {
+
let e = timelines_new.entry(*pos).or_insert(0);
+
*e += amount;
}
}
+
// for pos in 0..width as u64 {
+
// if splitters.contains(&pos) {
+
// print!("^");
+
// } else if timelines_new.contains_key(&pos) {
+
// print!("|");
+
// } else {
+
// print!(".");
+
// }
+
// }
+
// print!("\n\n");
+
swap(&mut timelines, &mut timelines_new);
+
timelines_new.clear();
}
timelines
};
-
println!("{}", timelines.len());
+
// println!("{:?}", timelines);
+
println!("{}", timelines.iter().fold(0, |acc, v| { acc + v.1 }))
}