-
Notifications
You must be signed in to change notification settings - Fork 0
/
wordleme.html
96 lines (94 loc) · 4.24 KB
/
wordleme.html
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<style>
.charcontainer{
display: flex;
width: 100%;
text-transform: uppercase;
}
.charinput{
/* width: 20%; */
flex: auto;
min-width: 0;
text-transform: uppercase;
}
</style>
<title>WordleMe</title>
</head>
<body>
<h3>known</h3>
<p class="charcontainer">
<input type="text" class="charinput singlechar" maxlength="1" id="known0">
<input type="text" class="charinput singlechar" maxlength="1" id="known1">
<input type="text" class="charinput singlechar" maxlength="1" id="known2">
<input type="text" class="charinput singlechar" maxlength="1" id="known3">
<input type="text" class="charinput singlechar" maxlength="1" id="known4">
</p>
<h3>wrong position</h3>
<p class="charcontainer">
<input type="text" class="charinput" id="wrongpos0">
<input type="text" class="charinput" id="wrongpos1">
<input type="text" class="charinput" id="wrongpos2">
<input type="text" class="charinput" id="wrongpos3">
<input type="text" class="charinput" id="wrongpos4">
</p>
<h3>can't have</h3>
<p class="charcontainer">
<input type="text" class="charinput" id="canthave">
</p>
<button onclick="findWords()">go!</button>
<div id="count"></div>
<ul id="output">
</ul>
<!-- <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script>
var words = [];
$.getJSON("5list.json")
.done(function( data ) {
words = data;
console.log(data.length + " 5-letter-words");
});
function findWords(){
// GET FORM DATA
var known = [$("#known0").val(), $("#known1").val(), $("#known2").val(), $("#known3").val(), $("#known4").val()];
var wrongpos = [$("#wrongpos0").val(), $("#wrongpos1").val(), $("#wrongpos2").val(), $("#wrongpos3").val(), $("#wrongpos4").val()]
var canthave = $("#canthave").val();
console.log(known, wrongpos,canthave);
// BUILD REGEX
var myregex = "(?=^";
for ( i = 0; i<5; i++)
if(known[i])
myregex+=known[i];
else if(wrongpos[i])
myregex+="(?!["+wrongpos[i]+"])[a-z]"
else
myregex+="[a-z]";
myregex+=")";
Array.from(wrongpos.join("")).forEach(element => {
myregex+="(?=.*"+element+")";
});
if(canthave)
myregex+="(?!.*["+canthave+"])";
console.log(myregex);
// FILTER
var re = new RegExp(myregex,"i");
var filtered_words = words.filter(word => re.test(word));
console.log(filtered_words.length + " matching criteria");
// OUTPUT
var canthave = $("#count").text(filtered_words.length + " matches");
$("#output").empty();
filtered_words.slice(0, 100).forEach(word =>
$("#output").append($("<li/>").text(word))
);
}
</script>
</body>
</html>