Finished part 2 day 4 lightning quick
This commit is contained in:
@@ -127,16 +127,57 @@ int main(){
|
||||
bingo_cards.push_back(card);
|
||||
}
|
||||
|
||||
bool found_result = false;
|
||||
|
||||
cout << "Best board score:" << endl;
|
||||
for(auto n : calls){
|
||||
for(auto& board: bingo_cards){
|
||||
bool r = board.call(n);
|
||||
if(r){
|
||||
cout << n << " * " << board.score() << " = " << n * board.score() << '\n';
|
||||
return 0;
|
||||
found_result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(found_result) break;
|
||||
}
|
||||
|
||||
// Now for part 2, find the worst board. So we go through all boards and see when they finish
|
||||
// Reset all boards first
|
||||
// Then go through all boards and do all calls on them and keep track of the #numbers needed
|
||||
|
||||
int worst_board = 0, calls_needed_worst_board = 0, current_board = 0;
|
||||
|
||||
for(auto& b : bingo_cards){
|
||||
for(int y = 0; y < 5; ++y){
|
||||
b.opens[y].fill(true);
|
||||
}
|
||||
|
||||
int calls_needed = 0;
|
||||
|
||||
for(auto c : calls){
|
||||
bool call_result = b.call(c);
|
||||
|
||||
if(call_result){
|
||||
if(calls_needed_worst_board < calls_needed){
|
||||
worst_board = current_board;
|
||||
calls_needed_worst_board = calls_needed;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
calls_needed++;
|
||||
}
|
||||
|
||||
current_board++;
|
||||
}
|
||||
|
||||
int last_call = calls[calls_needed_worst_board];
|
||||
int worst_board_score = bingo_cards[worst_board].score();
|
||||
|
||||
cout << "Worst board:" << endl;
|
||||
cout << last_call << " * " << worst_board_score << " = " << last_call * worst_board_score << endl;
|
||||
|
||||
cout << flush;
|
||||
|
||||
file_stream.close();
|
||||
|
||||
Reference in New Issue
Block a user