#!/usr/bin/python3.10

# WORDLE CHEAT IN PYTHON 3
# pyddle.py by nbauers@btinternet.com - (c) copy all you like ...

# -------------------------------------------------------------------------------------------------
# ---------------------------------- ENTER DATA HERE ----------------------------------------------
# -------------------------------------------------------------------------------------------------
# GREY LETERS            - any number of letters, any order
# BLUE / GREEN LETTERS   - 4, 5 or 6 letters please, correctly positioned, pad with spaces
# YELLOW LETTERS         - 4, 5 or 6 items please, correctly positioned
# ['bight', 'fight', 'hight', 'might', 'pight', 'wight']

grey_letters       = "yuiadlcn"
blue_letters       = "   o  "
yellow_letter_list = ['r', 'er', 'os', 's', 'e', 't']

# -------------------------------------------------------------------------------------------------
# ----------------------------- NO CHANGES BELOW THIS POINT ---------------------------------------
# -------------------------------------------------------------------------------------------------
yellow_letters = ""

for yellow in yellow_letter_list:    
  for letter in yellow:
    if not letter in yellow_letters:
      yellow_letters += letter
# -------------------------------------------------------------------------------------------------
# OPEN THE FILE OF KNOWN WORDS
len     = len(blue_letters)

if len == 4:
  with open("pyddle4.txt") as ff:
    words = ff.read().strip().split()
if len == 5:
  with open("pyddle5.txt") as ff:
    words = ff.read().strip().split()
if len == 6:
  with open("pyddle6.txt") as ff:
    words = ff.read().strip().split()

print('\n' * 40)    # Several blank lines

# GREY FILTER -------------------------------------------------------------------------------------  
# Remove all words containing grey letters
for grey_letter in grey_letters:
  for word in reversed(words):
    if grey_letter in word:
      words.remove(word)

# print("GREY FILTER EXCLUDING", grey_letters)
# print(words)
# print()

# BLUE FILTER ------------------------------------------------------------------------------------  
# Remove all words not containing blue letters in the correct positions

for word in reversed(words):
  index = -1;
  for letter in blue_letters:
    index += 1
    if blue_letters[index] != " " and word[index] != blue_letters[index]: 
      words.remove(word)
      break

# print("BLUE FILTER KEEPING", blue_letters)
# print(words)
# print()

# YELLOW FILTER PASS ONE - remove unwanted yellows ------------------------------------------------
index = -1;
for letters in yellow_letter_list:
  index +=  1
  for word in reversed(words):
    if letters != "":
      for letter in letters: 
        if word[index] == letter:
          words.remove(word)
          break

# print("YELLOW FILTER PASS ONE REMOVING", yellow_letter_list)
# print(words)
# print()

# YELLOW FILTER PASS TWO - keep wanted yellows ----------------------------------------------------
for letter in yellow_letters:
  for word in reversed(words):
    if not letter in word:
      words.remove(word)

# print("YELLOW FILTER PASS TWO INCLUDING", yellow_letter_list)
print("POTENTIAL ANSWERS")
print(words)
print()
print()
# -------------------------------------------------------------------------------------------------