mirror of
https://github.com/RussellChamp/advent-of-code-2025-cursor.git
synced 2026-10-28 08:02:33 +00:00
Optimize Days 1-8: 41% faster overall (39ms → 23ms)
This commit is contained in:
1 parent
6ff1349679
commit
b067baac3d
10 files changed
+230
-184
No files matched your search
+2
-4
@@ -1,5 +1,4 @@
|
||||
use itertools::Itertools;
|
||||
use std::collections::HashSet;
|
||||
|
||||
advent_of_code::solution!(2);
|
||||
|
||||
@@ -106,13 +105,12 @@ pub fn part_two(input: &str) -> Option<u64> {
|
||||
let ranges: Vec<(u64, u64)> = input.split(',').filter_map(parse_range).collect();
|
||||
let merged = merge_ranges(&ranges);
|
||||
|
||||
// Use a small HashSet only for deduplication within merged ranges
|
||||
// Use itertools::unique() for deduplication
|
||||
// (needed because same number can match multiple pattern lengths)
|
||||
let mut seen = HashSet::new();
|
||||
let sum: u64 = merged
|
||||
.iter()
|
||||
.flat_map(|&(start, end)| iter_invalid_part2(start, end))
|
||||
.filter(|&n| seen.insert(n))
|
||||
.unique()
|
||||
.sum();
|
||||
|
||||
Some(sum)
|
||||
|
||||
Reference in new issue
Block a user