diff --git a/src/cal/day06.rs b/src/cal/day06.rs index 8b7ddb0..d1f973b 100644 --- a/src/cal/day06.rs +++ b/src/cal/day06.rs @@ -7,13 +7,20 @@ pub(crate) fn router() -> Router { #[derive(serde::Serialize)] struct CountElf { elf: usize, + #[serde(rename = "elf on a shelf")] elf_on_a_shelf: usize, + #[serde(rename = "shelf with no elf on it")] shelf_with_no_elf: usize, } async fn count_elf(body: String) -> Json { let elf = body.matches("elf").count(); - let elf_on_a_shelf = body.matches("elf on a shelf").count(); + let elf_on_a_shelf = "elf on a shelf".as_bytes(); + let elf_on_a_shelf = body + .as_bytes() + .windows(14) + .filter(|&w| w == elf_on_a_shelf) + .count(); let shelf_with_no_elf = body.matches("shelf").count() - elf_on_a_shelf; Json(CountElf { elf,