Skip to content
Advertisement

Java program failing on specific test case [closed]

I wrote a java program that does basically what wordle does. Given 2 3×3 rows, for example

JavaScript

If the guess matches the answer (in this case index [0][0]), mark it as “green”
If the guess does NOT match the answer at the exact position, but it IS valid (for example A at answer[1][0] does not match guess[1][0] but is an answer at guess[0][1]) would be counted as “yellow”

Here is the code I currently have. It works in this test case and all other test cases except for one. I can’t seem to catch my error.

JavaScript

I’m not currently worried that much about the speed, it performs about as I expect for the simple implementation I’ve made.

Advertisement

Answer

This is what I came up with:

Pseudocode:

JavaScript

Code:

JavaScript

The output of the program is this:

JavaScript

The only letter that matches the letter at the current index is guess[0][0]. guess[0][1] and guess[0][2] are red because the letter Y cannot be found in the flattened aFlat string.

guess [1][x] is all yellows because the letter A is found on the flattened aFlat string, but not in the correct index location in the answer array.

Lastly, guess[2][x] is red because the letter Z is not found anywhere on the flattened aFlat string.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement