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
··· 1 1 use std::{ 2 - char, 3 2 collections::{HashMap, HashSet}, 3 + mem::swap, 4 4 }; 5 5 6 6 fn main() { 7 - let input = include_str!("../../input_example.txt").trim(); 7 + let input = include_str!("../../input.txt").trim(); 8 8 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()] 12 13 .iter() 13 14 .enumerate() 14 15 .map(|(i, line)| if i % 2 != 0 { "" } else { line }) ··· 18 19 .enumerate() 19 20 .fold(HashSet::new(), |mut s, (i, char)| { 20 21 if char == '^' { 21 - s.insert(i as u32); 22 + s.insert(i as u64); 22 23 } 23 24 s 24 25 }) ··· 26 27 .collect(); 27 28 28 29 let timelines = { 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(); 31 33 for splitters in splitters_map { 32 - for (timeline, pos) in timelines.clone() { 34 + for (pos, amount) in &timelines { 33 35 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); 37 + *m1 += amount; 38 + let p1 = timelines_new.entry(pos + 1).or_insert(0); 39 + *p1 += amount; 40 + } else { 41 + let e = timelines_new.entry(*pos).or_insert(0); 42 + *e += amount; 37 43 } 38 44 } 45 + // for pos in 0..width as u64 { 46 + // if splitters.contains(&pos) { 47 + // print!("^"); 48 + // } else if timelines_new.contains_key(&pos) { 49 + // print!("|"); 50 + // } else { 51 + // print!("."); 52 + // } 53 + // } 54 + // print!("\n\n"); 55 + swap(&mut timelines, &mut timelines_new); 56 + timelines_new.clear(); 39 57 } 40 58 timelines 41 59 }; 42 - println!("{}", timelines.len()); 60 + // println!("{:?}", timelines); 61 + println!("{}", timelines.iter().fold(0, |acc, v| { acc + v.1 })) 43 62 }