Counting anagrams | View | Download | |
Noughts and crosses | View | Download | |
Permutations | View | Download | |
Listing subsets | View | Download |
list_anagrams(word)
that returns a list of
all the anagrams of a given word, and another function
count_anagrams(word)
that uses a different method to calculate the
number of anagrams of a given word without actually listing them. (Here a "word"
just means a string of letters, not necessarily a real word.) Your task is
to write unit tests to check that these functions are working correctly. Things
that you could check include the following:
list_anagrams()
should be the same as the number returned by count_anagrams()
.
You could check this for a selection of your favourite words.
list_anagrams()
should contain the
original word. You could check this for a selection of your favourite words.
w
consists of the letter "a" repeated several times,
then there should only be one anagram, namely w
itself.
w
consists of the letter "a" repeated $n$ times
followed by the letter "b" repeated $m$ times, then the number of anagrams
should be the binomial coefficient $\binom{n+m}{n}$.
w
consists of the first $n$ letters of the
alphabet, then there should be $n!$ different anagrams. You cannot
reasonably check this for large values of $n$, but you could check it
for $n\leq 6$ say.
list_anagrams()
gives the correct answer.
list_subsets = list_subsets_a
to
list_subsets = list_subsets_b
or
list_subsets = list_subsets_c
or
list_subsets = list_subsets_d
, then run the notebook from the beginning.
You should see that the code runs without error for list_subsets_a
,
but that it fails for the other three functions. Read the output from the
unit tests carefully to see which tests are failing for which values of $n$
and $m$. Then try to work out why they are failing, using the VS Code debugger
if necessary. The functions list_subsets_b
and list_subsets_c
can be fixed by quite small changes. The function list_subsets_d
only fails one test, but it is not so easy to correct that.
git config --global user.name "Neil Strickland"
git config --global user.email "N.P.Strickland@sheffield.ac.uk"
zoopy
repository at
https://github.com/NeilStrickland/zoopy.
You will see that there are just four files there, which you can look at in your browser.
Now clone the repository to your computer. To do this, first click the green "Code" button
on the web page, which will expand a menu like this:
git clone https://github.com/NeilStrickland/zoopy.git
zoopy
in your main Python folder.
Use the File menu to open this subfolder (instead of your main Python folder) in
VS Code. You should see that it contains copies of the four files that you saw on the
web page.
pip install Pillow tk customtkinter
zoopy.py
in VS Code, and run it by clicking the
icon at the top right of the screen.
A new window should pop up, and you can interact with is as described on the
zoopy web page.
zoopy.py
, or the size
of the window at line 40, or some other parameters. Alternatively, you could
add to the list of spare emoji in the file emoji.txt
. If you
are more ambitious, you could work out how to make the window switch between
a white background and a black background when the user presses the comma
key (and modify the instructions in README.md
accordingly).