Skip to content

Commit 7827550

Browse files
committed
2025 02.2 | less stupid window function
1 parent cea5453 commit 7827550

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/aoc/y2025/day02.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,14 @@ pub fn part_2(data: crate::DataIn) -> crate::AoCResult<String> {
6262
let len = numstr.len();
6363
let max_len = len / 2;
6464

65-
// This takes 4 seconds but whatever 😭
6665
(1..=max_len)
6766
// Filter out any number that can't make valid windows
6867
.filter(|size| len % size == 0)
6968
.any(|size| {
7069
let substr = &numstr[0..size];
71-
numstr
72-
.chars()
73-
.chunks(size)
74-
.into_iter()
75-
.all(|window| window.collect::<String>() == substr)
70+
(size..=len - size)
71+
.step_by(size)
72+
.all(|start| &numstr[start..start + size] == substr)
7673
})
7774
})
7875
})

0 commit comments

Comments
 (0)