-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest1.js
43 lines (36 loc) · 1.03 KB
/
test1.js
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
34
35
36
37
38
39
40
41
42
43
const fs = require('fs');
// Function to check if a line on the bingo card is complete
function isLineComplete(line) {
return line.every(num => calledNumbers.includes(num));
}
// Function to check if any row or column on the bingo card is complete
function isBingo(card) {
// Check rows
for (let i = 0; i < 5; i++) {
if (isLineComplete(card[i])) {
return true;
}
}
// Check columns
for (let i = 0; i < 5; i++) {
const column = card.map(row => row[i]);
if (isLineComplete(column)) {
return true;
}
}
return false;
}
// Read called numbers from external file
const calledNumbers = fs.readFileSync('called_numbers.txt', 'utf-8')
.split(',')
.map(num => parseInt(num));
// Read bingo card from external file
const bingoCard = fs.readFileSync('bingo_card.txt', 'utf-8')
.split('\n')
.map(row => row.split(' ').map(num => parseInt(num)));
// Check if the card will ever get Bingo
if (isBingo(bingoCard)) {
console.log('Bingo is possible!');
} else {
console.log('No Bingo for this card.');
}