Created
January 12, 2022 15:50
-
-
Save jeremyfelt/e0a144a7ac54e2ddb3c879eaafd09ed9 to your computer and use it in GitHub Desktop.
My hacky little script to identify common character pairs in the Wordle word list.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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