cws/main_cw02.tex
author Christian Urban <christian.urban@kcl.ac.uk>
Sat, 14 Jan 2023 14:13:16 +0000
changeset 459 d59404a41d5f
parent 458 d9f8245d0861
child 475 59e005dcf163
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
420
4edc1a308652 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 415
diff changeset
     1
268
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
     2
% !TEX program = xelatex
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
\documentclass{article}
426
b51467741af2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 420
diff changeset
     4
\usepackage{../styles/style}
166
780c40aaad27 updated
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
     5
\usepackage{disclaimer}
426
b51467741af2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 420
diff changeset
     6
\usepackage{../styles/langs}
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
     7
\usepackage{graphicx}
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
\begin{document}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
329
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
    12
%% should ask to lower case the words.
8a34b2ebc8cc updated
Christian Urban <urbanc@in.tum.de>
parents: 316
diff changeset
    13
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    14
\section*{Evil Wordle Game (Scala, 7 Marks)}
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
420
4edc1a308652 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 415
diff changeset
    16
\mbox{}\hfill\textit{``C makes it easy to shoot yourself in the foot; C++ makes it harder,}\\
4edc1a308652 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 415
diff changeset
    17
\mbox{}\hfill\textit{ but when you do, it blows your whole leg off.''}\smallskip\\
4edc1a308652 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 415
diff changeset
    18
\mbox{}\hfill\textit{ --- Bjarne Stroustrup (creator of the C++ language)}\bigskip\bigskip
4edc1a308652 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 415
diff changeset
    19
4edc1a308652 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 415
diff changeset
    20
4edc1a308652 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 415
diff changeset
    21
264
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 259
diff changeset
    22
ecd989eee8bd updated
Christian Urban <urbanc@in.tum.de>
parents: 259
diff changeset
    23
\noindent
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    24
You are asked to implement a Scala program for making the popular Wordle game as difficult
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    25
as possible.\bigskip
50
9891c9fac37e updated
Christian Urban <urbanc@in.tum.de>
parents: 48
diff changeset
    26
349
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    27
\IMPORTANTNONE{}
202
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    28
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    29
\noindent
144
716042628398 updated
Christian Urban <urbanc@in.tum.de>
parents: 110
diff changeset
    30
Also note that the running time of each part will be restricted to a
202
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    31
maximum of 30 seconds on my laptop.
39
c6fe374a5fca updated
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    32
166
780c40aaad27 updated
Christian Urban <urbanc@in.tum.de>
parents: 163
diff changeset
    33
\DISCLAIMER{}
39
c6fe374a5fca updated
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    34
202
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    35
\subsection*{Reference Implementation}
45
8399976b77fe updated
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    36
349
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    37
Like the C++ part, the Scala part works like this: you push your files
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    38
to GitHub and receive (after sometimes a long delay) some automated
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    39
feedback. In the end we will take a snapshot of the submitted files
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    40
and apply an automated marking script to them.\medskip
45
8399976b77fe updated
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    41
268
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
    42
\noindent
306
Christian Urban <urbanc@in.tum.de>
parents: 301
diff changeset
    43
In addition, the Scala part comes with reference
Christian Urban <urbanc@in.tum.de>
parents: 301
diff changeset
    44
implementations in form of \texttt{jar}-files. This allows you to run
202
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    45
any test cases on your own computer. For example you can call Scala on
459
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 458
diff changeset
    46
the command line with the option \texttt{-cp wordle.jar} and then
202
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    47
query any function from the template file. Say you want to find out
349
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    48
what the function \texttt{} produces: for this you just need
396
3ffe978a5664 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 356
diff changeset
    49
to prefix it with the object name \texttt{M2}.  If you want to find out what
202
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    50
these functions produce for the list \texttt{List("a", "b", "b")},
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    51
you would type something like:
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
202
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    53
\begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small]
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    54
$ scala -cp wordle.jar
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    55
scala> val secretsURL =
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    56
     | """https://nms.kcl.ac.uk/christian.urban/wordle.txt"""
349
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
    57
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    58
scala> M2.get_wordle_list(secretsURL)
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    59
val res0: List[String] = List(aahed, aalii, ...)
202
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    60
\end{lstlisting}%$
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    61
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    62
\subsection*{Hints}
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    64
\noindent
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    65
Useful data functions: \texttt{Source.fromURL},
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    66
\texttt{Source.fromFile} for obtaining a webpage and reading a file,
301
c3b33c709696 updated
Christian Urban <urbanc@in.tum.de>
parents: 284
diff changeset
    67
\texttt{.getOrElse(..,..)} allows to query a Map, but also gives a
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    68
default value if the Map is not defined, a Map can be `updated' by
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    69
using \texttt{+}, \texttt{.contains} and \texttt{.filter} can test whether
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    70
an element is included in a list, and respectively filter out elements in a list,
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    71
\texttt{.sortBy(\_.\_2)} sorts a list of pairs according to the second
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    72
elements in the pairs---the sorting is done from smallest to highest,
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    73
\texttt{.groupBy} orders lists according to same elements
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    74
.
39
c6fe374a5fca updated
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    75
c6fe374a5fca updated
Christian Urban <urbanc@in.tum.de>
parents: 38
diff changeset
    76
202
f7bcb27d1940 updated
Christian Urban <urbanc@in.tum.de>
parents: 166
diff changeset
    77
\newpage
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
459
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 458
diff changeset
    80
\subsection*{Main Part 2 (7 Marks, file wordle.scala)}
48
7a6a75ea9738 updated
Christian Urban <urbanc@in.tum.de>
parents: 46
diff changeset
    81
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    82
You probably know the game of Wordle\footnote{\url{https://en.wikipedia.org/wiki/Wordle}}
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    83
where you are supposed to guess a five-letter word. The feedback for guesses can help
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    84
with the next guess (green letters are correct, orange letters are present, but in the
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    85
wrong place). For example:
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    86
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    87
\begin{center}
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    88
\includegraphics[scale=0.2]{../pics/w.jpeg}
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    89
\end{center}  
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    90
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    91
\noindent
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    92
The idea of the program to be implemented here is to make the Wordle game as evil as possible
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    93
by finding words that are the most difficult to guess. A word list of five-letter words is available
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    94
from 
148
ead6089209ba updated
Christian Urban <urbanc@in.tum.de>
parents: 147
diff changeset
    95
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    96
\begin{center}
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    97
\begin{tabular}{ll}  
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    98
  \url{https://nms.kcl.ac.uk/christian.urban/wordle.txt} & (78 KByte)\\
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
    99
\end{tabular}
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   100
\end{center}
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   101
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   102
\noindent
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   103
In your program you need to download this list and implement some
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   104
functions that in the end select the most difficult words (given an
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   105
input from the user).  If bandwidth is an issue for you, download the
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   106
file locally, but in the submitted version use \texttt{Source.fromURL}
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   107
instead of \texttt{Source.fromFile}.
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   108
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   109
\subsection*{Tasks}
45
8399976b77fe updated
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   110
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   111
\begin{itemize}
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   112
\item[(1)] Implement the function \pcode{get_wordle_list} which takes an
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   113
  URL-string as argument and requests the corresponding file. The function should
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   114
  return the word list appropriately broken up into lines.
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   115
  The result should be a list of strings (the lines in the file). In case
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   116
  the url does not produce a file, return the empty list.
458
d9f8245d0861 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 445
diff changeset
   117
d9f8245d0861 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 445
diff changeset
   118
  \textcolor{red}{
d9f8245d0861 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 445
diff changeset
   119
    In what follows we will use \texttt{secrets} to refer  to the list of words listed
d9f8245d0861 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 445
diff changeset
   120
    in \texttt{wordle.txt}.  
d9f8245d0861 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 445
diff changeset
   121
  }
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   122
  \mbox{}\hfill [0.5 Marks]
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   123
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   124
\item[(2)] Implement a polymorphic function \pcode{removeN}, which removes $n$ occurrences of an
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   125
  element from a list (if this element is less than $n$ times present, then remove all occurrences).
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   126
  For example
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   127
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   128
\begin{lstlisting}[numbers=none]
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   129
removeN(List(1,2,3,2,1), 3, 2)  => List(1, 2, 2, 1)
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   130
removeN(List(1,2,3,2,1), 2, 1)  => List(1, 3, 2, 1)
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   131
removeN(List(1,2,3,2,1), 2, 2)  => List(1, 3, 1)
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   132
removeN(List(1,2,3,2,1), 1, 1)  => List(2, 3, 2, 1)
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   133
removeN(List(1,2,3,2,1), 1, 3)  => List(2, 3, 2)
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   134
removeN(List(1,2,3,2,1), 0, 2)  => List(1, 2, 3, 2, 1)
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   135
\end{lstlisting}
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   136
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   137
Make sure you only remove at most $n$ occurrences of the element from the list.
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   138
This function should work for lists of integers but also lists of chars, strings etc.\\
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   139
  \mbox{}\hfill [0.5 Marks]
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   140
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   141
\item[(3)] Implement a function \pcode{score} that calculates the
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   142
  feedback for a word against a secret word using the rules of the
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   143
  Wordle game. The output of \pcode{score} should be a list of 5
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   144
  elements of type \pcode{Tip} representing three outcomes: a letter
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   145
  in the correct position, a letter that is present, but not in the
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   146
  correct position and a letter that is absent. For example given the
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   147
  secret word "chess" the score for the word "caves" is
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   148
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   149
\begin{lstlisting}[numbers=none]
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   150
List(Correct, Absent, Absent, Present, Correct)
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   151
\end{lstlisting}
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   152
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   153
  You have to be careful with multiple occurrences of letters. For example
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   154
  the secret "chess" with the guess "swiss" should produce
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   155
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   156
\begin{lstlisting}[numbers=none]
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   157
List(Absent, Absent, Absent, Correct, Correct)
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   158
\end{lstlisting}
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   159
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   160
even though the first 's' in "swiss" is present in the secret word, the 's' are already
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   161
`used up' by the two letters that are correct. To implement this you need to
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   162
implement first a function \pcode{pool} which calculates all the letters in
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   163
a secret that are not correct in a word. For example
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   164
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   165
\begin{lstlisting}[numbers=none]
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   166
  pool("chess", "caves")  => List(h, e, s)
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   167
  pool("chess", "swiss")  => List(c, h, e)
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   168
\end{lstlisting}
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   169
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   170
  Now the helper function \pcode{aux} can analyse the arguments secret and word recursively letter-by-letter and
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   171
  decide: if the letters are the same, then return \pcode{Correct} for the corresponding position.
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   172
  If they are not the same, but the letter is in the pool, then return \pcode{Present} and also remove
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   173
  this letter from the pool in the next recursive call of \pcode{aux}. Otherwise return \pcode{Absent} for the
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   174
  corresponding position. The function \pcode{score} is a wrapper for the function \pcode{aux}
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   175
  calling \pcode{aux} with the appropriate arguments (recall what is calculated with \pcode{pool}).\mbox{}\hfill [2 Marks]
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   176
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   177
\item[(4)] Implement a function \pcode{eval} that gives an integer value to each of the
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   178
  \pcode{Tip}s such that
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   179
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   180
  \begin{center}
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   181
  \begin{tabular}{lcl}  
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   182
    \textit{eval (Correct)} & $\dn$ & $10$\\
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   183
    \textit{eval (Present)} & $\dn$ & $1$\\
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   184
    \textit{eval (Absent)} & $\dn$ & $0$
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   185
  \end{tabular}                                   
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   186
  \end{center}  
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   187
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   188
  The function \pcode{iscore} then takes an output of \pcode{score} and sums
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   189
  up all corresponding values. For example for 
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   190
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   191
\begin{lstlisting}[numbers=none]
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   192
  iscore("chess", "caves")  => 21
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   193
  iscore("chess", "swiss")  => 20
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   194
\end{lstlisting}
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   195
  \mbox{}\hfill [0.5 Marks]
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   196
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   197
\item[(5)] The function \pcode{evil} takes a list of secrets (the list from Task 1)
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   198
  and a word as arguments, and calculates the list of words with the lowest
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   199
  score (remember we want to make the Wordle game as difficult as possible---therefore
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   200
  when the user gives us a word, we want to find the secrets that produce the lowest
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   201
  score). For this implement a helper function \pcode{lowest} that goes through
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   202
  the secrets one-by-one and calculates the score. The argument \pcode{current} is
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   203
  the score of the ``currently'' found secrets. When the function \pcode{lowest}
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   204
  is called for the first time then this will be set to the maximum integer value
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   205
  \pcode{Int.MaxValue}. The accumulator will be first empty. If a secret is found
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   206
  with the same score as \pcode{current} then this word is added to the accumulator.
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   207
  If the secret has a lower score, then the accumulator will be discarded and this
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   208
  secret will be the new accumulator. If the secret has a higher score, then it can be
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   209
  ignored. For example \pcode{evil} (the wrapper for \pcode{lowest}) generates
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   210
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   211
\begin{lstlisting}[numbers=none]
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   212
evil(secrets, "stent").length => 1907
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   213
evil(secrets, "hexes").length => 2966
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   214
evil(secrets, "horse").length => 1203
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   215
evil(secrets, "hoise").length => 971
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   216
evil(secrets, "house").length => 1228
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   217
\end{lstlisting}
45
8399976b77fe updated
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   218
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   219
where \pcode{secrets} is the list generated under Task 1.
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   220
In all cases above the iscore of the resulting secrets is 0, but this does not need to be the case
445
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   221
in general.
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   222
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   223
\color{red}
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   224
  Note that the template gives as type for \texttt{evil}:
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   225
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   226
  \begin{center}
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   227
  \texttt{def evil(secrets: List[String], word: String) = ???}  
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   228
  \end{center}
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   229
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   230
  where the return type is left unspecified. This return type is not needed when
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   231
  functions are not recursive---\texttt{evil} is meant to be just a wrapper that
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   232
  calls \texttt{lowest} with appropriate default arguments and returns whatever
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   233
  \texttt{lowest} returns. Therefore a return type is not needed. But a slightly
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   234
  more accurate template definition for \texttt{evil} is:\medskip\medskip
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   235
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   236
  \begin{minipage}{1.05\textwidth}
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   237
  \begin{center}
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   238
  \texttt{def evil(secrets: List[String], word: String) : List[String] = ???}  
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   239
  \end{center}
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   240
  \end{minipage}\medskip\medskip
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   241
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   242
  where also the return type is explicitly given.\\\color{black}
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   243
  \mbox{}\hfill [1.5 Marks]
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   244
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   245
\item[(6)] The secrets generated in Task 5 are the ones with the lowest score
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   246
  with respect to the word. You can think of these as the secrets that are furthest ``away'' from the
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   247
  given word. This is already quite evil for a secret word---remember we can choose
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   248
  a secret \emph{after} a user has given a first word. Now we want to make it
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   249
  even more evil by choosing words that have the most obscure letters. For this we
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   250
  calculate the frequency of how many times certain letters occur in our secrets
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   251
  list (see Task 1). The \emph{frequency} of the letter $c$, say, is given by the formula
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   252
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   253
  \begin{center}
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   254
  $\textit{freq(c)} \dn 1 - \frac{\textit{number of occurrences of c}}{\textit{number of all letters}}$  
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   255
  \end{center}  
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   256
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   257
  That means that letters that occur fewer times in our secrets have a higher frequency.
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   258
  For example the letter 'y' has the frequency 0.9680234350909651 while the much more
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   259
  often occurring letter 'e' has only 0.897286463151403 (all calculations should be done
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   260
  with Doubles).
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   261
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   262
  The function \pcode{frequencies} should calculate the frequencies for all lower-case letters
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   263
  by generating a Map from letters (\pcode{Char}) to Doubles (frequencies).\\ 
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   264
  \mbox{}\hfill [1 Mark]
148
ead6089209ba updated
Christian Urban <urbanc@in.tum.de>
parents: 147
diff changeset
   265
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   266
\item[(7)] In this task we want to use the output of \pcode{evil}, rank each string in the
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   267
  generated set and then filter out the strings that are ranked highest (the ones with the most obscure letters).
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   268
  This list of strings often contains only a single word, but in general there might be more (see below).
458
d9f8245d0861 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 445
diff changeset
   269
  First implement a function \pcode{rank} that takes a frequency map (from 6) and a string as arguments.
d9f8245d0861 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 445
diff changeset
   270
  \textcolor{red}{In the testcases, the frequency map is generated for all words in \texttt{secrets}, that is the
d9f8245d0861 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 445
diff changeset
   271
  whole list in \texttt{wordle.txt}.} The function  
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   272
  generates a rank by summing up all frequencies of the letters in the string. For example
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   273
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   274
\begin{lstlisting}[numbers=none]
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   275
rank(frequencies(secrets), "adobe") => 4.673604687018193
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   276
rank(frequencies(secrets), "gaffe") => 4.745205057045945
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   277
rank(frequencies(secrets), "fuzzy") => 4.898735738513722
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   278
\end{lstlisting}
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   279
445
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   280
  \color{red}
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   281
  The return type for \texttt{rank} is \texttt{Double}:
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   282
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   283
  \begin{center}
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   284
  \texttt{def rank(frqs: Map[Char, Double], s: String) : Double = ???}  
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   285
  \end{center}
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   286
  \color{black}
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   287
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   288
  Finally, implement a function \pcode{ranked_evil} that selects from the output of \pcode{evil}
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   289
  the string(s) which are highest ranked in evilness.
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   290
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   291
  
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   292
\begin{lstlisting}[numbers=none]
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   293
ranked_evil(secrets, "abbey") => List(whizz)
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   294
ranked_evil(secrets, "afear") => List(buzzy)
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   295
ranked_evil(secrets, "zincy") => List(jugum)
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   296
ranked_evil(secrets, "zippy") => List(chuff)
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   297
\end{lstlisting}
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   298
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   299
This means if the user types in "abbey" then the most evil word to choose as secret is ``whizz'' (according to
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   300
our calculations). This word has a zero \pcode{iscore} and the most obscure letters.
148
ead6089209ba updated
Christian Urban <urbanc@in.tum.de>
parents: 147
diff changeset
   301
445
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   302
\color{red}
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   303
  The return type for \texttt{ranked\_evil} is \texttt{List[String]}:
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   304
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   305
  \begin{center}
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   306
  \texttt{def ranked\_evil(secrets: List[String], word: String) : List[String] = ???}  
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   307
  \end{center}
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   308
  \color{black}
b73e7ce91c10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 428
diff changeset
   309
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   310
%
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   311
%\color{red}
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   312
%\section*{Correction with \texttt{ranked\_evil}}
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   313
%
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   314
%The testcases above are actually not the maximum, but the minimum! I will make sure
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   315
%that the task will count as solved when either the minimum (as above) or the maximum (as intended)
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   316
%is used. The correct solutions for the above testcases using the maximum are:
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   317
%\color{black}
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   318
%
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   319
%\begin{lstlisting}[numbers=none]
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   320
%ranked_evil(secrets, "beats") => List(fuzzy)
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   321
%ranked_evil(secrets, "vitae") => List(fuzzy)
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   322
%ranked_evil(secrets, "bento") => List(fuzzy)
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   323
%ranked_evil(secrets, "belts") => List(fuzzy)
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   324
%\end{lstlisting}
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   325
%
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   326
%\noindent \textcolor{red}{Some further testcases for the maximum are:}
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   327
%
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   328
%\begin{lstlisting}[numbers=none]
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   329
%ranked_evil(secrets, "abbey") => List(whizz)
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   330
%ranked_evil(secrets, "afear") => List(buzzy)
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   331
%ranked_evil(secrets, "zincy") => List(jugum)
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   332
%ranked_evil(secrets, "zippy") => List(chuff)
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   333
%\end{lstlisting}
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   334
% 
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   335
%
349
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   336
428
cdfa6a293453 updated solutions and templates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
   337
\mbox{}\hfill [1 Mark]  
203
eb188f9ac038 updated
Christian Urban <urbanc@in.tum.de>
parents: 202
diff changeset
   338
\end{itemize}
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   339
268
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents: 264
diff changeset
   340
\end{document} 
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   341
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   342
%%% Local Variables: 
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   343
%%% mode: latex
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   344
%%% TeX-master: t
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   345
%%% End: 
349
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   346
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   347
682611a0fb89 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 333
diff changeset
   348