Skip to content

Instantly share code, notes, and snippets.

@CSMastermind
Created November 26, 2023 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CSMastermind/faa7137be440d097cb4b3bb2a6c71ab1 to your computer and use it in GitHub Desktop.
Save CSMastermind/faa7137be440d097cb4b3bb2a6c71ab1 to your computer and use it in GitHub Desktop.
Full Deletable Word Finder
const fs = require('fs');
const wordListPath = require('word-list');
const wordArray = fs.readFileSync(wordListPath, 'utf8').split('\n');
const wordSet = new Set(wordArray);
function findFullyDeletableWords(words) {
const fullyDeletableWords = new Set();
words.forEach(word => {
console.log('Checking: ' + word);
let isFullyDeletable = true;
for (let i = 0; i < word.length; i++) {
let newWord = word.slice(0, i) + word.slice(i + 1);
//console.log('\tTrying: ' + newWord);
if (!words.has(newWord)) {
isFullyDeletable = false;
break; // The word is not fully deletable
}
}
if (isFullyDeletable) {
fullyDeletableWords.add(word);
}
});
return Array.from(fullyDeletableWords);
}
const fullyDeletableWords = findFullyDeletableWords(wordSet);
console.log("Fully deletable words found:", JSON.stringify(fullyDeletableWords, null, 2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment