This commit is contained in:
Aadi Desai 2023-12-01 16:31:53 +00:00
parent 769f5cb129
commit 638f878bd9
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM
2 changed files with 20 additions and 0 deletions

18
src/cal/day01.rs Normal file
View file

@ -0,0 +1,18 @@
use axum::{extract::Path, http::StatusCode, response::IntoResponse, routing::get, Router};
pub(crate) fn router() -> Router {
Router::new().route("/1/*ids", get(cube_bits))
}
async fn cube_bits(Path(ids): Path<String>) -> Result<impl IntoResponse, StatusCode> {
let res = ids
.split('/')
.map(|id| id.parse::<i32>())
.collect::<Result<Vec<_>, _>>()
.map_err(|_| StatusCode::BAD_REQUEST)?
.into_iter()
.fold(0i32, |acc, id| acc ^ id)
.pow(3)
.to_string();
Ok(res)
}

View file

@ -1,6 +1,8 @@
mod day00; mod day00;
mod day01;
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())
} }