# Wordle Helper - starter-word scorer and vowel counter
#
# A small helper for Wordle players. It scores opening guesses
# by letter frequency, counts vowels, and checks a guess against
# the pattern of a known answer. Written for today's puzzle,
# #1972 KARAT (Thursday, November 12, 2026), rated Medium.
# The answer is a noun meaning a unit of fineness of gold
# (1/24 part gold in an alloy), pattern KA__T, two vowels.
#
# Full daily hints, solver and difficulty guide:
# https://w...content-available-to-author-only...y.com/
#
# How to use it: run it as-is to see the starter rankings and
# the check for KARAT, or import score_word and count_vowels
# in your own Wordle tools.

VOWELS = "AEIOU"

# Letter frequencies in common English words, used to score
# an opening guess. E, A, R, I, O, T, N and S carry the most weight.
LETTER_FREQ = {
    "E": 12.0, "A": 9.1, "R": 8.0, "I": 7.3, "O": 6.9,
    "T": 6.6, "N": 6.5, "S": 6.4, "L": 5.8, "C": 5.2,
    "U": 4.5, "D": 4.3, "P": 3.7, "M": 3.4, "H": 3.3,
    "G": 2.9, "B": 2.6, "F": 2.3, "Y": 2.2, "W": 2.0,
    "K": 1.8, "V": 1.2, "X": 0.4, "Z": 0.3, "J": 0.3, "Q": 0.2,
}

STARTERS = ["CRANE", "SLATE", "STARE", "AUDIO", "RAISE"]


def count_vowels(word):
    """Return the number of vowels (A, E, I, O, U) in a word."""
    return sum(1 for ch in word.upper() if ch in VOWELS)


def score_word(word):
    """Score a guess: sum of letter frequencies, counting each
    distinct letter once so repeated letters do not inflate it."""
    return round(sum(LETTER_FREQ.get(ch, 0.0) for ch in set(word.upper())), 1)


def matches_pattern(word, pattern):
    """True if word fits a pattern such as KA__T, where _ is unknown."""
    if len(word) != len(pattern):
        return False
    return all(p == "_" or p == w for p, w in zip(pattern, word.upper()))


def main():
    print("Wordle #1972 - KARAT helper")
    print("Answer: KARAT, pattern KA__T, vowels:", count_vowels("KARAT"))
    print()
    print("Starter-word scores (higher is better):")
    for word in sorted(STARTERS, key=score_word, reverse=True):
        print(" ", word, "vowels:", count_vowels(word), "score:", score_word(word))
    print()
    print("Does KARAT match KA__T?", matches_pattern("KARAT", "KA__T"))
    print("Does PARTY match KA__T?", matches_pattern("PARTY", "KA__T"))


if __name__ == "__main__":
    main()
