Last active
January 24, 2022 11:50
-
-
Save Leko/098674d7a571fd139bcffd73eedff707 to your computer and use it in GitHub Desktop.
Wordle solver Node.js example
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
#!/usr/bin/env node | |
const readline = require("node:readline"); | |
async function guess(feedbacks) { | |
// You can use `console.error` for debugging. | |
console.error(feedbacks); | |
// Write your solver! | |
return "count"; | |
} | |
/** | |
* Wordle solver interface | |
* | |
* STDIN: response from the Wordle | |
* STDOUT: word to input to the Wordle | |
* STDERR: you can output any value for debugging | |
*/ | |
async function main() { | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
crlfDelay: Infinity, | |
}); | |
const feedbacks = []; | |
let word = await guess([]); | |
console.log(word); // the first word | |
for await (const line of rl) { | |
switch (line) { | |
case "NOT_IN_WORD_LIST": | |
throw new Error("You should guess another word"); | |
default: { | |
const response = line.trim().split(","); | |
if (response.every((r) => r === "correct")) { | |
break; | |
} | |
feedbacks.push({ response, word }); | |
word = await guess(feedbacks); | |
console.log(word); // the second and subsequent words. | |
} | |
} | |
} | |
} | |
main(); |
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
{ | |
"name": "@your-scope/wordle-solver", | |
"version": "1.0.0", | |
"publishConfig": { | |
"access": "public" | |
}, | |
"bin": "./index.js" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment