Advertisement
ZEdKasat

Wordle Solver

Feb 24th, 2022
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | None | 0 0
  1. does_not_contain = set()
  2. does_contain = set()
  3.  
  4. def check_contains(word):
  5.     for char in does_contain:
  6.         if char not in word:
  7.             return False
  8.     return True
  9.  
  10. def check_does_not_contain(word):
  11.     for char in does_not_contain:
  12.         if char in word:
  13.             return False
  14.     return True
  15.  
  16. def check_exact(word):
  17.     x = 0
  18.     while x < len(exact):
  19.         if exact[x].isalpha() and exact[x] != word[x]:
  20.             return False
  21.         x += 1
  22.     return True
  23.  
  24. def check_exact_mismatch(word):
  25.     x = 0
  26.     while x < len(exact_mistmatch):
  27.         if exact_mistmatch[x].isalpha() and exact_mistmatch[x] == word[x]:
  28.             return False
  29.         x += 1
  30.     return True
  31.  
  32. with open("filtered_words.txt", "r") as file:
  33.     word_list = file.read().split()
  34.  
  35. while True:
  36.  
  37.     word = input("Word Entered: ")
  38.     grey = input("Greys: ")
  39.     yellow = input("Yellows: ")
  40.     green = input("Greens: ")
  41.     for char in grey:
  42.         does_not_contain.add(char)
  43.     for char in yellow+green:
  44.         does_contain.add(char)
  45.  
  46.     word = list(word)
  47.     exact, exact_mistmatch = word.copy(), word.copy()
  48.     for i in range(len(word)):
  49.         if word[i] not in green:
  50.             exact[i] = "0"
  51.         if word[i] not in yellow:
  52.             exact_mistmatch[i] = "0"
  53.  
  54.     rem_words = []
  55.     for x in word_list:
  56.         if (check_contains(x) and check_does_not_contain(x) and check_exact(x) and check_exact_mismatch(x)):
  57.             rem_words.append(x)
  58.     word_list = rem_words.copy()
  59.     print(word_list)
  60.  
  61.  
  62. # Great -ans
  63. # Treat - try
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement