Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
My hacky little script to identify common character pairs in the Wordle word list.
// See https://jeremyfelt.com/2022/01/12/a-wordle-character-pair-strategy/
const words = []; // Populate with word list.
const wordScores = [];
const pairPositions = [];
const positionText =[ "first", "second", "third", "last" ];
words.forEach( word => {
let position = 0;
while ( position < 4 ) {
let pair = word.slice( position, position + 2 );
let log = pairPositions.find( item => item.pair === pair );
if ( 'undefined' === typeof log ) {
pairPositions.push( {
pair,
'first': 0,
'second': 0,
'third': 0,
'last': 0,
'total': 0,
} );
log = pairPositions.find( item => item.pair === pair );
}
log[ positionText[ position ] ]++;
log.total++;
position++;
}
} );
words.forEach( word => {
let position = 0;
let score = 0;
while ( position < 4 ) {
let pair = word.slice(position, position + 2);
let log = pairPositions.find( item => item.pair === pair );
score = score + log.total;
position++;
}
wordScores.push( { word, score } );
} );
// Output the top 20 words.
console.log( wordScores.sort( ( a, b ) => a.score < b.score ).slice( 0, 20 ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment