mirror of
https://github.com/supleed2/cch23-8bit.git
synced 2024-12-22 14:05:48 +00:00
Day 1
This commit is contained in:
parent
769f5cb129
commit
638f878bd9
18
src/cal/day01.rs
Normal file
18
src/cal/day01.rs
Normal 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)
|
||||||
|
}
|
|
@ -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())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue