-
Notifications
You must be signed in to change notification settings - Fork 3
/
benchmarks.js
34 lines (27 loc) · 935 Bytes
/
benchmarks.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
const words = require('./src/data/words.json');
const { getBestGuess, getSoundGuesses } = require('./src/wordle');
const { compareWords } = require('./src/words');
reportBenchmarks();
function reportBenchmarks() {
const results = new Map();
for (const word of words) {
const result = getResult(word);
const key = result.passed ? result.currentRow : 'X';
results.set(key, results.has(key) ? results.get(key) + 1 : 1);
}
console.log(results);
}
function getResult(word) {
let currWords = words;
let comparison;
let currentRow = 0;
do {
const guess = getBestGuess(currWords);
comparison = compareWords(guess, word);
currWords = getSoundGuesses(currWords, guess, comparison);
} while (currentRow++ < Number.POSITIVE_INFINITY && !isPassed(comparison));
return { currentRow, passed: isPassed(comparison) };
}
function isPassed(comparison) {
return comparison.every((val) => val === 2);
}