YVW3YMAVOW4LQJTWN277BJCJXGUJHEOPEZHT2XGCNJJTU5WKSJNAC
itertools = "0.10.3"
fn parse_testcase(content: Lines<BufReader<File>>) -> Result<Vec<i32>, Error> {
Ok(content
.filter(Result::is_ok)
.map(Result::unwrap)
.map(|line| line.parse::<i32>())
.map(Result::unwrap)
.collect())
fn parse_testcase(mut content: Lines<BufReader<File>>) -> Result<TestCase, Error> {
let numbers: Vec<u8> = content
.next()
.unwrap().unwrap()
.split(",")
.map(|n| n.parse::<u8>())
.filter(Result::is_ok)
.map(Result::unwrap)
.collect();
let boards: Vec<Vec<u8>> = content
.map(Result::unwrap)
.flat_map(|line| line.split(" "))
.map(|n| n.parse::<u8>().unwrap())
.collect::<Vec<u8>>()
.into_iter()
.chunks(25)
.into_iter()
.map(|chunk| chunk.collect())
.collect();
Ok(TestCase::new(boards, numbers))
.collect::<()>();
.for_each(drop);
}
pub fn did_already_win(&self) -> bool {
self.check_rows_for_win() || self.check_columns_for_win()
}
fn get_rows(&self) -> Vec<[Cell; 5]> {
(0..5)
.map(|row| [self.numbers[row * 5], self.numbers[row * 5 + 1], self.numbers[row * 5 + 2], self.numbers[row * 5 + 3], self.numbers[row * 5 + 4]])
.collect()
pub fn solve() {}
pub fn new(numbers: Vec<Vec<u8>>, balls: Vec<u8>) -> TestCase{
TestCase {
boards: numbers.into_iter().map(Board::new).collect(),
balls: balls
}
}
pub fn solve(&self) -> &Board {
self.balls
.into_iter()
.take_while(|x| {
self.boards.iter().for_each(|board| board.mark(x));
self.boards.iter().any(|board| board.did_already_win())
});
self.boards.iter().find(|board| board.did_already_win()).unwrap()
}