-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwordle.js
76 lines (67 loc) · 1.48 KB
/
wordle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function print(string){
console.log(string)
}
const fs = require("fs");
answerList=[]
allowedList=[]
var inputs=["texts","midge","break","hello","lynch","adieu"]
var found=false
var word
var triesLeft=6
var input
async function getFile(file){
return await fs.promises.readFile(file, "utf-8")
}
async function getWords(){
data = await getFile("./wordle-allowed-guesses.txt")
allowedList=data.split(/\r\n|\n\r|\n|\r/)
data = await getFile("./wordle-answers-alphabetical.txt")
answerList=data.split(/\r\n|\n\r|\n|\r/)
word= answerList[Math.floor(Math.random()*answerList.length)];
}
function inputCheck() {
if (input.length==5){
if (allowedList.includes(input)){
allowed=true
}
}
}
function inputProcessing(){
inputList=input.split("")
print(inputList)
wordList=word.split("")
print(wordList)
triesLeft=triesLeft-1
for (let i = 0; i < 5; i++) {
if (inputList[i]==wordList[i]){
output[i]="Y"
}
}
for (let i = 0; i < 5; i++) {
if (wordList.includes(inputList[i])){
if (foundLetters.includes(inputList[i])==false){
if (output[i]!="Y"){
output[i]="C"
}
}
}
}
}
async function main(){
await getWords()
while (triesLeft>0 && found==false){
input=inputs[triesLeft-1]
output=["N","N","N","N","N"]
foundLetters=[]
allowed=false
inputCheck()
if (allowed){
print(triesLeft)
inputProcessing()
}else{
print("INVALID IMPUT")
}
print(output)
}
}
main()