From 119bad49f1d2b2314d748219593d6f627e359c2c Mon Sep 17 00:00:00 2001 From: Soup For My Family Date: Mon, 8 Jun 2026 04:15:46 -0600 Subject: [PATCH] Better iteration --- src/wordle.zig | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/wordle.zig b/src/wordle.zig index f9c08f9..2eb80ff 100644 --- a/src/wordle.zig +++ b/src/wordle.zig @@ -1,21 +1,21 @@ /// The length of Wordle words. -const WordLen = 5; +pub const WordLen = 5; /// A single Wordle word (ASCII). -const Word = [WordLen]u8; +pub const Word = [WordLen]u8; /// The type of string literals representing words. -const WordLiteral = *const [WordLen:0]u8; +pub const WordLiteral = *const [WordLen:0]u8; /// A clue for a spot given a guess. -const Clue = enum { +pub const Clue = enum { Gray, Yellow, Green, }; /// The list of clues for a full guess. -const Clues = [WordLen]Clue; +pub const Clues = [WordLen]Clue; /// Guesses a word given a solution and returns the clues. pub fn checkGuess(guess: Word, solution: Word) Clues { @@ -23,7 +23,7 @@ pub fn checkGuess(guess: Word, solution: Word) Clues { var clues: Clues = undefined; // compare each letter pairwise - for (guess, 0..WordLen) |guessLetter, idx| { + for (guess, 0..) |guessLetter, idx| { // if letters match, the clue is green if (guessLetter == solution[idx]) { clues[idx] = Clue.Green; @@ -34,7 +34,7 @@ pub fn checkGuess(guess: Word, solution: Word) Clues { clues[idx] = Clue.Gray; // if a matching letter in the solution can be found, write yellow - for (solution, 0..WordLen) |solutionLetter, _| { + for (solution) |solutionLetter| { if (guessLetter == solutionLetter) { clues[idx] = Clue.Yellow; break; @@ -47,7 +47,7 @@ pub fn checkGuess(guess: Word, solution: Word) Clues { } /// Converts a fixed-length string literal into a word. -fn strToWord(str: WordLiteral) Word { +pub fn strToWord(str: WordLiteral) Word { var buffer: Word = undefined; @memcpy(&buffer, str); return buffer; @@ -64,9 +64,9 @@ fn expectGuessClues(guess: WordLiteral, solution: WordLiteral, expectClues: Word const clues = checkGuess(guessWord, solutionWord); // confirm that the expected clues match the clues - for (clues, 0..) |clue, idx| { + for (clues, expectCluesWord) |clue, expectedChar| { // convert character to associated clue variant - const expected = switch (expectCluesWord[idx]) { + const expected = switch (expectedChar) { ' ' => Clue.Gray, 'Y' => Clue.Yellow, 'G' => Clue.Green,