From c0ccbe15102757b6277a4ba730510bfd01f017e3 Mon Sep 17 00:00:00 2001
From: Allen Downey 8.12.3. Exercise“Wordle” is an online word game where the objective is to guess a five-letter word in six or fewer attempts.
Each attempt has to be recognized as a word, not including proper nouns.
After each attempt, you get information about which of the letters you guessed appear in the target word, and which ones are in the correct position.
For example, suppose the target word is MOWER
and you guess TRIED
. You would learn that E
is in the word and in the correct position, R
is in the word but not in the correct position, and T
, I
, and D
are not in the word.
As a different example, suppose you have guessed the words SPADE
and CLERK
, and you’ve learned that E
is in the word, but not in either of those positions, and none of the other letters appear in the word.
Of the words in the word list, how many could be the target word?
-Write a function called check_word
that takes a five-letter word and checks whether it could be the target word.
For example, suppose the target word is MOWER
and you guess TRIED
.
+You would learn that E
is in the word and in the correct position, R
is in the word but not in the correct position, and T
, I
, and D
are not in the word.
As a different example, suppose you have guessed the words SPADE
and CLERK
, and you’ve learned that E
is in the word, but not in either of those positions, and none of the other letters appear in the word.
+Of the words in the word list, how many could be the target word?
+Write a function called check_word
that takes a five-letter word and checks whether it could be the target word, given these guesses.
You can use any of the functions from the previous chapter, like uses_any
.
In particular, he says it is “shameless in its repetition of the same adjective,” and mentions in particular the number of times “its characters either shudder or turn pale.”
-To see whether his objection is valid, let’s count the number number of times the word pale
appears in any form, including pale
, pales
, paled
, and paleness
, as well as the related word pallor
.
+
To see whether his objection is valid, let’s count the number number of lines that contain the word pale
in any form, including pale
, pales
, paled
, and paleness
, as well as the related word pallor
.
Use a single regular expression that matches all of these words and no others.
Copyright 2024 Allen B. Downey