fix day 4
This commit is contained in:
parent
6577bae991
commit
fb8ec81683
@ -1,3 +1,4 @@
|
|||||||
|
use std::fmt;
|
||||||
use color_eyre::eyre;
|
use color_eyre::eyre;
|
||||||
use eyre::eyre;
|
use eyre::eyre;
|
||||||
|
|
||||||
@ -127,6 +128,28 @@ impl Board {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Board {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
for row in self.squares {
|
||||||
|
write!(f, "|")?;
|
||||||
|
for (i, sq) in row.iter().enumerate() {
|
||||||
|
let dt = sq.draw_time.map(|dt| format!("{}", dt)).unwrap_or(String::from("__"));
|
||||||
|
write!(f, "({}: {})", sq.value, dt)?;
|
||||||
|
if i < 4 {
|
||||||
|
write!(f, ", ")?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
write!(f, "|\n")?;
|
||||||
|
}
|
||||||
|
if self.bingo_time.is_some() {
|
||||||
|
write!(f, "Bingo: ({}: {})", self.bingo_value.unwrap(), self.bingo_time.unwrap())
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
write!(f, "Bingo: (__: __)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fn load(data: &str) -> eyre::Result<Vec<Board>> {
|
fn load(data: &str) -> eyre::Result<Vec<Board>> {
|
||||||
let mut lines = data.lines().peekable();
|
let mut lines = data.lines().peekable();
|
||||||
@ -147,6 +170,7 @@ fn load(data: &str) -> eyre::Result<Vec<Board>> {
|
|||||||
if squares.len() == 25 {
|
if squares.len() == 25 {
|
||||||
boards.push(Board::from(&squares)?);
|
boards.push(Board::from(&squares)?);
|
||||||
boards.last_mut().unwrap().set_bingo();
|
boards.last_mut().unwrap().set_bingo();
|
||||||
|
squares.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user