diff -r 3e5d8657302f -r fc72f3ab3a57 cws/cw02.tex --- a/cws/cw02.tex Fri Nov 17 02:13:40 2017 +0000 +++ b/cws/cw02.tex Fri Nov 17 09:13:03 2017 +0000 @@ -257,7 +257,13 @@ 1728. A $6\times 6$ board is already too large to be searched exhaustively.\footnote{For your interest, the number of tours on $6\times 6$, $7\times 7$ and $8\times 8$ are 6637920, 165575218320, - 19591828170979904, respectively.} + 19591828170979904, respectively.}\bigskip + +\noindent +\textbf{Hints:} useful list functions: \texttt{.contains(..)} checks whether an +element is in a list, \texttt{.flatten} turns a list of lists into just a list, +\texttt{\_::\_} puts an element on the head of the list, \texttt{.head} gives you the +first element of a list (make sure the list is not \texttt{Nil}) \subsubsection*{Tasks (file knight2.scala)} @@ -294,9 +300,17 @@ \noindent \textbf{Testing} The first tour function will be called with board -sizes of up to $8 \times 8$. +sizes of up to $8 \times 8$. +\bigskip -%%\newpage +\noindent +\textbf{Hints:} a useful list function: \texttt{.filter(..)} filters a list according +to a boolean function; a useful option function: \texttt{.isDefined} returns true, +if an option is \texttt{Some(..)}; anonymous functions can be constructed using +\texttt{(x:Int) => ...}, this functions takes an \texttt{Int} as argument + + +\newpage \subsection*{Part 2 (3 Marks)} As you should have seen in Part 1, a naive search for tours beyond @@ -353,6 +367,15 @@ otherwise you will get problems with stack-overflows.\\ \mbox{}\hfill[1 Mark] \end{itemize} +\bigskip + +\noindent +\textbf{Hints:} a useful list function: \texttt{.sortBy} sorts a list according +to a component given by the function; a function can be tested to be tail +recursive by annotation \texttt{@tailrec}, which is made available by +importing \texttt{scala.annotation.tailrec} + + \end{document}