Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64882d2cf2 | ||
|
|
8691afa048 |
+3
-13
@@ -62,18 +62,8 @@ fn loadDict() []const Wordle.Word {
|
|||||||
// TODO: binary search? need to assert that words are sorted
|
// TODO: binary search? need to assert that words are sorted
|
||||||
pub fn isInDictionary(word: Wordle.Word) bool {
|
pub fn isInDictionary(word: Wordle.Word) bool {
|
||||||
// exhaustively search through dictionary
|
// exhaustively search through dictionary
|
||||||
for (getDictionary()) |entry| {
|
for (getDictionary()) |*entry| {
|
||||||
// compare each letter at a time
|
if (std.mem.eql(u8, entry, &word)) {
|
||||||
var match = true;
|
|
||||||
for (entry, word) |entryLetter, wordLetter| {
|
|
||||||
if (entryLetter != wordLetter) {
|
|
||||||
match = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if every letter matches, return a complete match
|
|
||||||
if (match) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,7 +83,7 @@ fn expectNotDictionary(word: Wordle.WordLiteral) !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "in dictionary" {
|
test "in dictionary" {
|
||||||
try expectDictionary("abash");
|
try expectDictionary("aback");
|
||||||
}
|
}
|
||||||
|
|
||||||
test "not in dictionary" {
|
test "not in dictionary" {
|
||||||
|
|||||||
Reference in New Issue
Block a user