1
Fork 0
advent-of-code/source/year_2021/day_04/mod.rs

28 lines
708 B
Rust

//! Day 04 of 2021.
mod bingo;
mod board;
use bingo::Bingo;
use crate::prelude::*;
/// Get the solution for day 04 of 2021.
pub fn solution() -> Solution {
Solution::new(Day::new(4, 2021), part_1, part_2).with_expected(8580, 9576)
}
/// The logic to solve part one.
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())
}
/// The logic to solve part two.
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())
}