2 ms·
Wordle programs often start with a similar bug in their (similar) scoring function. Apart from tracking positions and consuming them as you suggested, there's a
by svat 3y ago
Wordle programs often start with a similar bug in their (similar) scoring function. Apart from tracking positions and consuming them as you suggested, there's also another approach to writing the scoring function, suggested by Knuth's notation in the paper mentioned in another comment:
from collections import Counter
def score_guess(guess, secret_code):
red = sum(guess[i] == secret_code[i] for i in range(len(guess)))
total = (Counter(guess) & Counter(secret_code)).total()
return (red, total - red)
assert score_guess('YYYY', 'XXXY') == (1, 0)
assert score_guess('YYYX', 'XXXY') == (0, 2)
(The `&` on `Counter` computes minimum of the two counts.)