23 lines
580 B
Rust
23 lines
580 B
Rust
|
mod bingo;
|
||
|
mod board;
|
||
|
|
||
|
use bingo::Bingo;
|
||
|
|
||
|
use crate::prelude::*;
|
||
|
|
||
|
pub fn solution() -> Solution {
|
||
|
Solution::new(Day::new(4, 2021), part_1, part_2).with_expected(8580, 9576)
|
||
|
}
|
||
|
|
||
|
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())
|
||
|
}
|
||
|
|
||
|
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())
|
||
|
}
|