mirror of
https://github.com/supleed2/cch23-8bit.git
synced 2024-12-22 14:05:48 +00:00
Day 6 fixes
This commit is contained in:
parent
dbb73b6bb3
commit
79ab2f9787
|
@ -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<CountElf> {
|
||||
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,
|
||||
|
|
Loading…
Reference in a new issue