2024-01-14 21:04:10 +00:00
|
|
|
//! Day 04 of 2021.
|
|
|
|
|
2022-10-02 20:20:09 +00:00
|
|
|
mod bingo;
|
|
|
|
mod board;
|
|
|
|
|
|
|
|
use bingo::Bingo;
|
|
|
|
|
|
|
|
use crate::prelude::*;
|
|
|
|
|
2024-01-14 21:04:10 +00:00
|
|
|
/// Get the solution for day 04 of 2021.
|
2022-10-02 20:20:09 +00:00
|
|
|
pub fn solution() -> Solution {
|
|
|
|
Solution::new(Day::new(4, 2021), part_1, part_2).with_expected(8580, 9576)
|
|
|
|
}
|
|
|
|
|
2024-01-14 21:04:10 +00:00
|
|
|
/// The logic to solve part one.
|
2022-10-02 20:20:09 +00:00
|
|
|
fn part_1(input: &str) -> Result<String> {
|
|
|
|
let (winning_board, latest_number) =
|
|
|
|
Bingo::from_str(input)?.play_until_first_win();
|
|
|
|
Ok((winning_board.sum_unmarked() * latest_number).to_string())
|
|
|
|
}
|
|
|
|
|
2024-01-14 21:04:10 +00:00
|
|
|
/// The logic to solve part two.
|
2022-10-02 20:20:09 +00:00
|
|
|
fn part_2(input: &str) -> Result<String> {
|
|
|
|
let (winning_board, latest_number) =
|
|
|
|
Bingo::from_str(input)?.play_until_last_win();
|
|
|
|
Ok((winning_board.sum_unmarked() * latest_number).to_string())
|
|
|
|
}
|