Skip to content

Instantly share code, notes, and snippets.

@Leko
Last active January 24, 2022 11:50
Show Gist options
  • Save Leko/098674d7a571fd139bcffd73eedff707 to your computer and use it in GitHub Desktop.
Save Leko/098674d7a571fd139bcffd73eedff707 to your computer and use it in GitHub Desktop.
Wordle solver Node.js example
#!/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();
{
"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