import fs from 'node:fs'; import wordlistEnglish from 'wordlist-english'; const validTwo = new Set([ 'am', 'an', 'as', 'at', 'be', 'by', 'do', 'go', 'he', 'hi', 'if', 'in', 'is', 'it', 'me', 'my', 'no', 'of', 'oh', 'on', 'or', 'so', 'to', 'up', 'us', 'we' ]); // Build a clean, high-frequency recognized vocabulary for client-side unlimited/custom puzzles const vocabulary = new Set(); for (const word of wordlistEnglish.english) { const w = word.toLowerCase().trim(); if (w.length === 2 && validTwo.has(w)) { vocabulary.add(w); } else if (w.length >= 3 && w.length <= 16 && /^[a-z]+$/.test(w)) { vocabulary.add(w); } } console.log('Total vocabulary words:', vocabulary.size); // Pack into space-separated string or array const sortedWords = [...vocabulary].sort(); const lexiconContent = `// Client-side recognized English words for solver & custom puzzles // Loaded as a Set for O(1) instantaneous lookup const RAW_LEXICON = ${JSON.stringify(sortedWords)}; export const DICTIONARY_SET = new Set(RAW_LEXICON); // Prefix set for lightning fast tree-pruning search (1 to 6 chars) export const PREFIX_SET = new Set(); for (const word of RAW_LEXICON) { for (let len = 1; len <= Math.min(word.length, 6); len++) { PREFIX_SET.add(word.slice(0, len)); } } export function isWordValid(word) { return DICTIONARY_SET.has(word.toLowerCase()); } `; fs.writeFileSync('src/data/lexicon.js', lexiconContent, 'utf8'); console.log('Saved src/data/lexicon.js successfully!');