diff -r 7a0735db4788 -r b73e7ce91c10 cws/main_cw02.tex --- a/cws/main_cw02.tex Mon Nov 14 12:04:21 2022 +0000 +++ b/cws/main_cw02.tex Thu Nov 17 11:34:50 2022 +0000 @@ -213,7 +213,28 @@ where \pcode{secrets} is the list generated under Task 1. In all cases above the iscore of the resulting secrets is 0, but this does not need to be the case -in general.\\ +in general. + +\color{red} + Note that the template gives as type for \texttt{evil}: + + \begin{center} + \texttt{def evil(secrets: List[String], word: String) = ???} + \end{center} + + where the return type is left unspecified. This return type is not needed when + functions are not recursive---\texttt{evil} is meant to be just a wrapper that + calls \texttt{lowest} with appropriate default arguments and returns whatever + \texttt{lowest} returns. Therefore a return type is not needed. But a slightly + more accurate template definition for \texttt{evil} is:\medskip\medskip + + \begin{minipage}{1.05\textwidth} + \begin{center} + \texttt{def evil(secrets: List[String], word: String) : List[String] = ???} + \end{center} + \end{minipage}\medskip\medskip + + where also the return type is explicitly given.\\\color{black} \mbox{}\hfill [1.5 Marks] \item[(6)] The secrets generated in Task 5 are the ones with the lowest score @@ -249,6 +270,14 @@ rank(frequencies(secrets), "fuzzy") => 4.898735738513722 \end{lstlisting} + \color{red} + The return type for \texttt{rank} is \texttt{Double}: + + \begin{center} + \texttt{def rank(frqs: Map[Char, Double], s: String) : Double = ???} + \end{center} + \color{black} + Finally, implement a function \pcode{ranked_evil} that selects from the output of \pcode{evil} the string(s) which are highest ranked in evilness. @@ -263,6 +292,14 @@ This means if the user types in "abbey" then the most evil word to choose as secret is ``whizz'' (according to our calculations). This word has a zero \pcode{iscore} and the most obscure letters. +\color{red} + The return type for \texttt{ranked\_evil} is \texttt{List[String]}: + + \begin{center} + \texttt{def ranked\_evil(secrets: List[String], word: String) : List[String] = ???} + \end{center} + \color{black} + % %\color{red} %\section*{Correction with \texttt{ranked\_evil}}