I tend to play a daily wordle, comparing notes with coworkers.
Every once in a while I have 3 letters green, but no idea what goes in the other two places. Small enough that it's possible yet annoying to run the permutations in my head. So earlier I would write little scripts to do that which I finally decided to enhance with a UI...
it was interesting to generalize the hardcoded cases from earlier:
function permutate(){
const bads = window.bads.value.toLowerCase();
const goods = alphabet.split('').filter(x=>bads.indexOf(x) === -1);
const word = window.word.value.toLowerCase();
const parts = word.split('_');
if(word.length !== 5 || parts.length !== 3) {
alert('expected word to be 5 letters with two _s');
return;
}
const perms = [];
goods.forEach(a=>{goods.forEach(b=>perms.push(`${parts[0]}${a}${parts[1]}${b}${parts[2]}`))});
window.results.innerHTML = perms.join('\n');
}
No comments:
Post a Comment