From 79ab2f978709867c2552f84cc796ebaa34c2c4ec Mon Sep 17 00:00:00 2001 From: Aadi Desai <21363892+supleed2@users.noreply.github.com> Date: Tue, 12 Dec 2023 00:40:11 +0000 Subject: [PATCH] Day 6 fixes --- src/cal/day06.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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,