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

28 lines
675 B
Rust

use std::str::FromStr;
use color_eyre::Result;
mod bingo;
mod board;
use bingo::Bingo;
pub fn solve() -> Result<()> {
let input_data = include_str!("../../data/day_04.txt").trim();
println!("Day 04 Part 1: {}", part_1(input_data)?);
println!("Day 04 Part 2: {}", part_2(input_data)?);
Ok(())
}
fn part_1(input: &str) -> Result<i32> {
let (winning_board, latest_number) =
Bingo::from_str(input)?.play_until_first_win();
Ok(winning_board.sum_unmarked() * latest_number)
}
fn part_2(input: &str) -> Result<i32> {
let (winning_board, latest_number) =
Bingo::from_str(input)?.play_until_last_win();
Ok(winning_board.sum_unmarked() * latest_number)
}