cws/main_cw02.tex
changeset 445 b73e7ce91c10
parent 428 cdfa6a293453
child 458 d9f8245d0861
equal deleted inserted replaced
444:7a0735db4788 445:b73e7ce91c10
   211 evil(secrets, "house").length => 1228
   211 evil(secrets, "house").length => 1228
   212 \end{lstlisting}
   212 \end{lstlisting}
   213 
   213 
   214 where \pcode{secrets} is the list generated under Task 1.
   214 where \pcode{secrets} is the list generated under Task 1.
   215 In all cases above the iscore of the resulting secrets is 0, but this does not need to be the case
   215 In all cases above the iscore of the resulting secrets is 0, but this does not need to be the case
   216 in general.\\
   216 in general.
       
   217 
       
   218 \color{red}
       
   219   Note that the template gives as type for \texttt{evil}:
       
   220 
       
   221   \begin{center}
       
   222   \texttt{def evil(secrets: List[String], word: String) = ???}  
       
   223   \end{center}
       
   224 
       
   225   where the return type is left unspecified. This return type is not needed when
       
   226   functions are not recursive---\texttt{evil} is meant to be just a wrapper that
       
   227   calls \texttt{lowest} with appropriate default arguments and returns whatever
       
   228   \texttt{lowest} returns. Therefore a return type is not needed. But a slightly
       
   229   more accurate template definition for \texttt{evil} is:\medskip\medskip
       
   230 
       
   231   \begin{minipage}{1.05\textwidth}
       
   232   \begin{center}
       
   233   \texttt{def evil(secrets: List[String], word: String) : List[String] = ???}  
       
   234   \end{center}
       
   235   \end{minipage}\medskip\medskip
       
   236 
       
   237   where also the return type is explicitly given.\\\color{black}
   217   \mbox{}\hfill [1.5 Marks]
   238   \mbox{}\hfill [1.5 Marks]
   218 
   239 
   219 \item[(6)] The secrets generated in Task 5 are the ones with the lowest score
   240 \item[(6)] The secrets generated in Task 5 are the ones with the lowest score
   220   with respect to the word. You can think of these as the secrets that are furthest ``away'' from the
   241   with respect to the word. You can think of these as the secrets that are furthest ``away'' from the
   221   given word. This is already quite evil for a secret word---remember we can choose
   242   given word. This is already quite evil for a secret word---remember we can choose
   247 rank(frequencies(secrets), "adobe") => 4.673604687018193
   268 rank(frequencies(secrets), "adobe") => 4.673604687018193
   248 rank(frequencies(secrets), "gaffe") => 4.745205057045945
   269 rank(frequencies(secrets), "gaffe") => 4.745205057045945
   249 rank(frequencies(secrets), "fuzzy") => 4.898735738513722
   270 rank(frequencies(secrets), "fuzzy") => 4.898735738513722
   250 \end{lstlisting}
   271 \end{lstlisting}
   251 
   272 
       
   273   \color{red}
       
   274   The return type for \texttt{rank} is \texttt{Double}:
       
   275 
       
   276   \begin{center}
       
   277   \texttt{def rank(frqs: Map[Char, Double], s: String) : Double = ???}  
       
   278   \end{center}
       
   279   \color{black}
       
   280 
   252   Finally, implement a function \pcode{ranked_evil} that selects from the output of \pcode{evil}
   281   Finally, implement a function \pcode{ranked_evil} that selects from the output of \pcode{evil}
   253   the string(s) which are highest ranked in evilness.
   282   the string(s) which are highest ranked in evilness.
   254 
   283 
   255   
   284   
   256 \begin{lstlisting}[numbers=none]
   285 \begin{lstlisting}[numbers=none]
   260 ranked_evil(secrets, "zippy") => List(chuff)
   289 ranked_evil(secrets, "zippy") => List(chuff)
   261 \end{lstlisting}
   290 \end{lstlisting}
   262 
   291 
   263 This means if the user types in "abbey" then the most evil word to choose as secret is ``whizz'' (according to
   292 This means if the user types in "abbey" then the most evil word to choose as secret is ``whizz'' (according to
   264 our calculations). This word has a zero \pcode{iscore} and the most obscure letters.
   293 our calculations). This word has a zero \pcode{iscore} and the most obscure letters.
       
   294 
       
   295 \color{red}
       
   296   The return type for \texttt{ranked\_evil} is \texttt{List[String]}:
       
   297 
       
   298   \begin{center}
       
   299   \texttt{def ranked\_evil(secrets: List[String], word: String) : List[String] = ???}  
       
   300   \end{center}
       
   301   \color{black}
   265 
   302 
   266 %
   303 %
   267 %\color{red}
   304 %\color{red}
   268 %\section*{Correction with \texttt{ranked\_evil}}
   305 %\section*{Correction with \texttt{ranked\_evil}}
   269 %
   306 %