Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calculate_pattern function does not take into account duplicate letters #2

Closed
MarkCBell opened this issue Feb 13, 2022 · 2 comments
Closed

Comments

@MarkCBell
Copy link

For example, calculate_pattern('meets', 'weary') currently returns (0, 2, 1, 0, 0), however the correct pattern should be (0, 2, 0, 0, 0) since there is not a second e in the target word. One way to do this correctly is:

from collections import Counter

def calculate_pattern(guess, true):
    '''Yield the pattern that Wordle would return if you guessed `guess` and the true word is `true`'''
    yellows = Counter(true)
    for x, y in zip(guess, true):
        if x == y:
            yield 2
        elif yellows[x] > 0:
            yield 1
        else:
            yield 0
        yellows[x] -= 1

you just need to then call this as tuple(calculate_pattern(word, word2)).

@GillesVandewiele
Copy link
Owner

Wow, thank you so much for spotting this. I implemented your fix (and credited you in the code)

@gbotev1
Copy link

gbotev1 commented Feb 14, 2022

I think you need to do two passes in order to also catch corner cases like calculate_pattern('rower', 'goner'), which currently returns (1, 2, 0, 2, 2) instead of (0, 2, 0, 2, 2).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants