This commit is contained in:
Aadi Desai 2023-12-06 14:37:31 +00:00
parent 0e264593c6
commit 0dade3be25
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM
2 changed files with 25 additions and 0 deletions

23
src/cal/day06.rs Normal file
View file

@ -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<CountElf> {
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,
})
}

View file

@ -1,10 +1,12 @@
mod day00; mod day00;
mod day01; mod day01;
mod day04; mod day04;
mod day06;
pub(crate) fn router() -> axum::Router { pub(crate) fn router() -> axum::Router {
axum::Router::new() axum::Router::new()
.nest("/", day00::router()) .nest("/", day00::router())
.nest("/", day01::router()) .nest("/", day01::router())
.nest("/", day04::router()) .nest("/", day04::router())
.nest("/", day06::router())
} }