diff --git a/src/cal/day06.rs b/src/cal/day06.rs new file mode 100644 index 0000000..5c1bdc4 --- /dev/null +++ b/src/cal/day06.rs @@ -0,0 +1,23 @@ +use axum::{extract::Json, routing::post, Router}; + +pub(crate) fn router() -> Router { + Router::new().route("/6", post(count_elf)) +} + +#[derive(serde::Serialize)] +struct CountElf { + elf: usize, + elf_on_a_shelf: usize, + 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 shelf_with_no_elf = body.matches("shelf").count() - elf_on_a_shelf; + Json(CountElf { + elf, + elf_on_a_shelf, + shelf_with_no_elf, + }) +} diff --git a/src/cal/mod.rs b/src/cal/mod.rs index 52a3bd8..b302856 100644 --- a/src/cal/mod.rs +++ b/src/cal/mod.rs @@ -1,10 +1,12 @@ mod day00; mod day01; mod day04; +mod day06; pub(crate) fn router() -> axum::Router { axum::Router::new() .nest("/", day00::router()) .nest("/", day01::router()) .nest("/", day04::router()) + .nest("/", day06::router()) }