Soo... I guess I'm playing Bingo this time? Should be interesting. Maybe I can finally make a class, or at least a struct.
~
Bah. The leaderboards are already full. That's fine I Guess. I'm doing it a slower way. Though I don't think I'll ever get onto a leaderboard. I'm in it to get through it, not to get kudos. At least that's what I'll keep telling myself.
Anyway, parsing and constructing the boards was easy, and the checking code wasn't too bad either. Wish I knew a more elegant way of checking this; Python would make this SUPER easy.
bool checkBoard (BOARD board) {
// Check rows
for (auto row : board) {
bool pass = true;
for (auto space : row) {
if (space == -1) continue;
pass = false;
break;
}
if (pass) return true;
}
// Check columns (trickier?)
for (int i = 0; i < 5; i++) {
bool pass = true;
for (int j = 0; j < 5; j++) {
if (board.at(j).at(i) == -1) continue;
pass = false;
break;
}
if (pass) return true;
}
return false;
}
The rest was just replacing the callout values with -1
on each board, checking each board, and when one finally passes the checkBoard
function, that's the winner! Sum it up, got the answer!
// Run simulation
for (auto callout : numbers) {
// Mark called out number
for (int i = 0; i < boards.size(); i++)
for (int j = 0; j < 5; j++)
for (int k = 0; k < 5; k++)
if (boards[i][j][k] == callout)
boards[i][j][k] = -1;
// Check boards for a winner
for (int b = 0; b < boards.size(); b++) {
if (checkBoard(boards[b])) {
// Calculate sum of winning board
int sum = 0;
for (auto row : boards[b])
for (auto num : row)
if (num != -1)
sum += num;
cout << "Winner!"
}
}
}
I think I'm going to make some hot buttered rum before I move on to the second part.
Okay. A small update to the code for this, to get the LAST board that will win. Interesting...
New strategy then: when a winning board is identified, REMOVE IT from the list of boards. If it's the last board, that's the one I want. Otherwise, keep going.
if (boards.size() > 1) {
// Remove board from consideration
boards.erase(boards.begin() + b--);
} else {
// Normal winning logic
}
Honestly, the smallest amount of changes I've made for a part B so far. Neat!