73 functions that in the end select the most difficult words (given an |
73 functions that in the end select the most difficult words (given an |
74 input from the user). If bandwidth is an issue for you, download the |
74 input from the user). If bandwidth is an issue for you, download the |
75 file locally, but in the submitted version use \texttt{Source.fromURL} |
75 file locally, but in the submitted version use \texttt{Source.fromURL} |
76 instead of \texttt{Source.fromFile}. |
76 instead of \texttt{Source.fromFile}. |
77 |
77 |
|
78 |
78 \subsection*{Tasks} |
79 \subsection*{Tasks} |
79 |
80 |
80 \begin{itemize} |
81 \begin{itemize} |
81 \item[(1)] Implement the function \pcode{get_wordle_list} which takes an |
82 \item[(1)] Implement the function \pcode{get_wordle_list} which takes an |
82 URL-string as argument and requests the corresponding file. The function should |
83 URL-string as argument and requests the corresponding file. The function should |
83 return the word list appropriately broken up into lines. |
84 return the word list appropriately broken up into lines. |
84 The result should be a list of strings (the lines in the file). In case |
85 The result should be a list of strings (the lines in the file). In case |
85 the url does not produce a file, return the empty list.\\ |
86 the url does not produce a file, return the empty list. |
86 \mbox{}\hfill [0.25 Marks] |
87 |
87 |
88 In what follows we will use \texttt{secrets} to refer to the list of words listed |
88 \item[(2)] Implement a polymorphic function \pcode{removeN}, which removes $n$ occurences of an |
89 in \texttt{wordle.txt}. |
89 element from a list (if this element is less than $n$ times pressent, then remove all occurences). |
90 |
|
91 \mbox{}\hfill [0.5 Marks] |
|
92 |
|
93 \item[(2)] Implement a polymorphic function \pcode{removeN}, which removes $n$ occurrences of an |
|
94 element from a list (if this element is less than $n$ times present, then remove all occurrences). |
90 For example |
95 For example |
91 |
96 |
92 \begin{lstlisting}[numbers=none] |
97 \begin{lstlisting}[numbers=none] |
93 removeN(List(1,2,3,2,1), 3, 2) => List(1, 2, 2, 1) |
98 removeN(List(1,2,3,2,1), 3, 2) => List(1, 2, 2, 1) |
94 removeN(List(1,2,3,2,1), 2, 1) => List(1, 3, 2, 1) |
99 removeN(List(1,2,3,2,1), 2, 1) => List(1, 3, 2, 1) |
95 removeN(List(1,2,3,2,1), 2, 2) => List(1, 3, 1) |
100 removeN(List(1,2,3,2,1), 2, 2) => List(1, 3, 1) |
96 removeN(List(1,2,3,2,1), 1, 1) => List(2, 3, 2, 1) |
101 removeN(List(1,2,3,2,1), 1, 1) => List(2, 3, 2, 1) |
97 removeN(List(1,2,3,2,1), 1, 3) => List(2, 3, 2) |
102 removeN(List(1,2,3,2,1), 1, 3) => List(2, 3, 2) |
98 removeN(List(1,2,3,2,1), 0, 2) => List(1, 2, 3, 2, 1) |
103 removeN(List(1,2,3,2,1), 0, 2) => List(1, 2, 3, 2, 1) |
|
104 removeN(List("1","2","3","2","1"), "1", 1) |
|
105 => List("2","3","2","1") |
99 \end{lstlisting} |
106 \end{lstlisting} |
100 |
107 |
101 Make sure you only remove at most $n$ occurrences of the element from the list. |
108 Make sure you only remove at most $n$ occurrences of the element from the list. |
102 This function should work for lists of intergers but also lists of chars, strings etc.\\ |
109 This function should work for lists of integers but also lists of chars, strings etc.\\ |
103 \mbox{}\hfill [0.25 Marks] |
110 \mbox{}\hfill [0.5 Marks] |
104 |
111 |
105 \item[(3)] Implement a function \pcode{score} that calculates the |
112 \item[(3)] Implement a function \pcode{score} that calculates the |
106 feedback for a word against a secret word using the rules of the |
113 feedback for a word against a secret word using the rules of the |
107 Wordle game. The output of \pcode{score} should be a list of 5 |
114 Wordle game. The output of \pcode{score} should be a list of 5 |
108 elements of type \pcode{Tip} representing three outcomes: a letter |
115 elements of type \pcode{Tip} representing three outcomes: a letter |
180 evil(secrets, "house").length => 1228 |
187 evil(secrets, "house").length => 1228 |
181 \end{lstlisting} |
188 \end{lstlisting} |
182 |
189 |
183 where \pcode{secrets} is the list generated under Task 1. |
190 where \pcode{secrets} is the list generated under Task 1. |
184 In all cases above the iscore of the resulting secrets is 0, but this does not need to be the case |
191 In all cases above the iscore of the resulting secrets is 0, but this does not need to be the case |
185 in general.\\ |
192 in general. |
|
193 |
186 \mbox{}\hfill [1.5 Marks] |
194 \mbox{}\hfill [1.5 Marks] |
187 |
195 |
188 \item[(6)] The secrets generated in Task 5 are the ones with the lowest score |
196 \item[(6)] The secrets generated in Task 5 are the ones with the lowest score |
189 with respect to the word, or the secrets that are furthest ``away'' from the |
197 with respect to the word. You can think of these as the secrets that are furthest ``away'' from the |
190 given word. This is already quite evil for a secret word---remember we can choose |
198 given word. This is already quite evil for a secret word---remember we can choose |
191 a secret \emph{after} a user has given a first word. Now we want to make it |
199 a secret \emph{after} a user has given a first word. Now we want to make it |
192 even more evil by choosing words that have the most obscure letters. For this we |
200 even more evil by choosing words that have the most obscure letters. For this we |
193 calculate the frequency of how many times certain letters occur in our secrets |
201 calculate the frequency of how many times certain letters occur in our secrets |
194 list (see Task 1). The \emph{frequency} of the letter $c$, say, is given by the formula |
202 list (see Task 1). The \emph{frequency} of the letter $c$, say, is given by the formula |
207 \mbox{}\hfill [1 Mark] |
215 \mbox{}\hfill [1 Mark] |
208 |
216 |
209 \item[(7)] In this task we want to use the output of \pcode{evil}, rank each string in the |
217 \item[(7)] In this task we want to use the output of \pcode{evil}, rank each string in the |
210 generated set and then filter out the strings that are ranked highest (the ones with the most obscure letters). |
218 generated set and then filter out the strings that are ranked highest (the ones with the most obscure letters). |
211 This list of strings often contains only a single word, but in general there might be more (see below). |
219 This list of strings often contains only a single word, but in general there might be more (see below). |
212 First implement a function \pcode{rank} that takes a frequency map (from 6) and a string as arguments and |
220 First implement a function \pcode{rank} that takes a frequency map (from 6) and a string as arguments. |
|
221 In the testcases, the frequency map is generated for all words in \texttt{secrets}, that is the |
|
222 whole list in \texttt{wordle.txt}. The function |
213 generates a rank by summing up all frequencies of the letters in the string. For example |
223 generates a rank by summing up all frequencies of the letters in the string. For example |
214 |
224 |
215 \begin{lstlisting}[numbers=none] |
225 \begin{lstlisting}[numbers=none] |
216 rank(frequencies(secrets), "adobe") => 4.673604687018193 |
226 rank(frequencies(secrets), "adobe") => 4.673604687018193 |
217 rank(frequencies(secrets), "gaffe") => 4.745205057045945 |
227 rank(frequencies(secrets), "gaffe") => 4.745205057045945 |
227 ranked_evil(secrets, "afear") => List(buzzy) |
237 ranked_evil(secrets, "afear") => List(buzzy) |
228 ranked_evil(secrets, "zincy") => List(jugum) |
238 ranked_evil(secrets, "zincy") => List(jugum) |
229 ranked_evil(secrets, "zippy") => List(chuff) |
239 ranked_evil(secrets, "zippy") => List(chuff) |
230 \end{lstlisting} |
240 \end{lstlisting} |
231 |
241 |
232 This means if the user types in "abbey" then the most evil word to choose as secret is "whizzy" (according to |
242 This means if the user types in "abbey" then the most evil word to choose as secret is ``whizz'' (according to |
233 our calculations). This word has a zero \pcode{iscore} and the most obscure letters. |
243 our calculations). This word has a zero \pcode{iscore} and the most obscure letters. |
234 |
|
235 % |
|
236 %\color{red} |
|
237 %\section*{Correction with \texttt{ranked\_evil}} |
|
238 % |
|
239 %The testcases above are actually not the maximum, but the minimum! I will make sure |
|
240 %that the task will count as solved when either the minimum (as above) or the maximum (as intended) |
|
241 %is used. The correct solutions for the above testcases using the maximum are: |
|
242 %\color{black} |
|
243 % |
|
244 %\begin{lstlisting}[numbers=none] |
|
245 %ranked_evil(secrets, "beats") => List(fuzzy) |
|
246 %ranked_evil(secrets, "vitae") => List(fuzzy) |
|
247 %ranked_evil(secrets, "bento") => List(fuzzy) |
|
248 %ranked_evil(secrets, "belts") => List(fuzzy) |
|
249 %\end{lstlisting} |
|
250 % |
|
251 %\noindent \textcolor{red}{Some further testcases for the maximum are:} |
|
252 % |
|
253 %\begin{lstlisting}[numbers=none] |
|
254 %ranked_evil(secrets, "abbey") => List(whizz) |
|
255 %ranked_evil(secrets, "afear") => List(buzzy) |
|
256 %ranked_evil(secrets, "zincy") => List(jugum) |
|
257 %ranked_evil(secrets, "zippy") => List(chuff) |
|
258 %\end{lstlisting} |
|
259 % |
|
260 % |
|
261 |
244 |
262 \mbox{}\hfill [1 Mark] |
245 \mbox{}\hfill [1 Mark] |
263 \end{itemize} |
246 \end{itemize} |
264 |
247 |
265 \end{document} |
248 \end{document} |