#!/usr/bin/python3.10

# WORDHURDLE CHEAT IN PYTHON 3
# pyddle6.py by nbauers@btinternet.com - copy all you like ...
# Data for WORDHURDLE:    https://www.bestwordlist.com/6letterwords.htm

# Here are the guesses
# arisen
# cloudy
# GUESS 2 USES NO LETTERS FROM GUESS 1
# GUESS 3 USES NO LETTERS FROM GUESSES 1 AND 2
# viable    arisen is a good initial word
# pounds    plough is a good second word
# rhythm
# regard

# -------------------------------------------------------------------------------------------------
# ---------------------------------- ENTER DATA HERE ----------------------------------------------
# -------------------------------------------------------------------------------------------------
# GREY LETERS    - ANY ORDER
# BLUE LETTERS   - Six characters in order. Use spaces if unknown
# YELLOW LETTERS - Correctly positioned

grey_letters       = "eruasdn"
blue_letters       = "     y"        
yellow_letter_list = ['c', 'l', 'io', '', '', '']

# -------------------------------------------------------------------------------------------------
# ----------------------------- 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
with open("pyddle6.txt") as ff:
  words = ff.read().strip().split()

# 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('\n' * 40)

# 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()
# -------------------------------------------------------------------------------------------------