Skip to content

Commit e3ebec4

Browse files
committed
perf(05/2015): simplify and improve performance
1 parent b0983d6 commit e3ebec4

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
| [Day 2: I Was Told There Would Be No Math](src/solutions/year2015/day02.rs) | ⭐⭐ | 0.074 | 0.105 |
9292
| [Day 3: Perfectly Spherical Houses in a Vacuum](src/solutions/year2015/day03.rs) | ⭐⭐ | 0.358 | 0.373 |
9393
| [Day 4: The Ideal Stocking Stuffer](src/solutions/year2015/day04.rs) | ⭐⭐ | 66.769 | 1931.428 |
94-
| [Day 5: Doesn't He Have Intern-Elves For This?](src/solutions/year2015/day05.rs) | ⭐⭐ | 0.261 | 3.733 |
94+
| [Day 5: Doesn't He Have Intern-Elves For This?](src/solutions/year2015/day05.rs) | ⭐⭐ | 0.261 | 0.987 |
9595

9696
# TODO
9797

src/solutions/year2015/day05.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,10 @@ impl Day05 {
4848
}
4949

5050
fn pair_twice(&self, word: &str) -> bool {
51-
let vec = word.chars().collect_vec();
52-
53-
for (i, w) in vec.windows(2).enumerate() {
54-
let pair = format!("{}{}", w[0], w[1]);
55-
56-
for j in i + 2..vec.len() - 1 {
57-
if pair == format!("{}{}", vec[j], vec[j + 1]) {
58-
return true;
59-
}
60-
}
61-
}
62-
63-
false
51+
word.chars().tuple_windows().any(|(c1, c2)| {
52+
let pair = format!("{}{}", c1, c2);
53+
word.matches(&pair).count() >= 2
54+
})
6455
}
6556

6657
fn repeated_with_letter_between(&self, word: &str) -> bool {

0 commit comments

Comments
 (0)