(Analysis by Darren Yao)

To find the number of green squares, we iterate over the positions of the 3x3 grids, incrementing the answer if they share the same letter.

Then, we find the number of yellow squares by finding the number of total highlighted squares and then subtracting the number of green squares. For each letter, the number of highlighted squares with that letter is the minimum of the number of times it appears in the guess and the number of times it appears in the answer. Summing over all letters yields the total number of highlighted squares, from which we subtract the number of green squares to get the answer.

Here is Danny Mittal's code.


import java.io.IOException;

public class Herdle {

public static void main(String[] args) throws IOException {
int[] freqCorrect = new int;
int[] freqGuess = new int;
int green = 0;
for (int j = 0; j < 9; j++) {
if (correct.charAt(j) == guess.charAt(j)) {
green++;
}
freqCorrect[correct.charAt(j) - 'A']++;
freqGuess[guess.charAt(j) - 'A']++;
}
int yellow = 0;
for (int j = 0; j < 26; j++) {
yellow += Math.min(freqCorrect[j], freqGuess[j]);
}
yellow -= green;
System.out.println(green);
System.out.println(yellow);
}
}