This is slightly faster...
[pyutils.git] / examples / wordle / wordle.py
index e5b6c6f7cb0f5be899a881face9a3d32a7ed8024..bf8dd36ee1d2265eb6b0a428ba15e00425ba6440 100755 (executable)
@@ -24,7 +24,7 @@ from pyutils.files import file_utils
 from pyutils.parallelize import executors
 from pyutils.parallelize import parallelize as par
 from pyutils.parallelize import smart_future
-from pyutils.typez import histogram
+from pyutils.types import histogram
 
 logger = logging.getLogger(__name__)
 args = config.add_commandline_args(
@@ -90,19 +90,19 @@ For example:
 args.add_argument(
     '--solutions_file',
     type=str,
-    default='/home/scott/bin/wordle_solutions.txt',
+    default='wordle_solutions.txt',
     help='Where can I find a valid word list for solutions?',
 )
 args.add_argument(
     '--guesses_file',
     type=str,
-    default='/home/scott/bin/wordle_guesses.txt',
+    default='wordle_guesses.txt',
     help='Where can I find a valid word list for guesses?',
 )
 args.add_argument(
     '--hash_file',
     type=str,
-    default='/home/scott/bin/wordle_hash.txt',
+    default='wordle_hash.txt',
     help='Where can I find my precomputed hash file?',
 )
 
@@ -655,11 +655,6 @@ class AutoPlayer(object):
                 if letter in word_state.letters_excluded:
                     return False
 
-                # If we already tried this letter in this position and
-                # it wasn't green, this isn't a possible solution.
-                if n in word_state.letters_at_unknown_positions[letter]:
-                    return False
-
                 # If we know a letter is in a position, solution words
                 # must have that letter in that position.
                 if (
@@ -667,6 +662,12 @@ class AutoPlayer(object):
                     and letter != word_state.letters_at_known_positions[n]
                 ):
                     return False
+
+                # If we already tried this letter in this position and
+                # it wasn't green, this isn't a possible solution.
+                if n in word_state.letters_at_unknown_positions[letter]:
+                    return False
+
                 letters_seen[letter] += 1
 
             # Finally, the word must include all letters presently