-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathpart-two.js
More file actions
33 lines (27 loc) · 783 Bytes
/
part-two.js
File metadata and controls
33 lines (27 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const { input } = require('./input');
const { Bingo } = require('./bingo.js');
const { cyan } = require('colors/safe');
let game = new Bingo(input.numbers, input.boards);
let winning_boards;
let boards_remaining = input.boards.length;
while (boards_remaining > 0) {
winning_boards = game.pickNext();
if (winning_boards) {
boards_remaining -= winning_boards.length;
}
}
let [winning_board, ...rest] = winning_boards;
if (rest.length > 0) {
throw new Error('More than one board won last!');
}
console.log(
'Called:\n' +
game.called
.map((num) => (winning_board.has(num) ? cyan(num) : num))
.join(' ') +
'\n'
);
console.log('Board Num:', winning_board.id);
winning_board.print(game.called);
console.log('-----');
console.log(winning_board.getScore(game.called));