cws/cw02.tex
changeset 149 3a6f51bc6121
parent 148 ead6089209ba
child 150 9a2f2a1de42b
equal deleted inserted replaced
148:ead6089209ba 149:3a6f51bc6121
     1 \documentclass{article}
     1 \documentclass{article}
     2 \usepackage{chessboard}
     2 \usepackage{chessboard}
     3 \usepackage[LSBC4,T1]{fontenc}
     3 \usepackage[LSBC4,T1]{fontenc}
       
     4 \let\clipbox\relax
     4 \usepackage{../style}
     5 \usepackage{../style}
     5 
     6 
     6 \begin{document}
     7 \begin{document}
     7 
     8 
     8 \setchessboard{smallboard,
     9 \setchessboard{smallboard,
   258 exhaustively.\footnote{For your interest, the number of tours on
   259 exhaustively.\footnote{For your interest, the number of tours on
   259   $6\times 6$, $7\times 7$ and $8\times 8$ are 6637920, 165575218320,
   260   $6\times 6$, $7\times 7$ and $8\times 8$ are 6637920, 165575218320,
   260   19591828170979904, respectively.}\bigskip
   261   19591828170979904, respectively.}\bigskip
   261 
   262 
   262 \noindent
   263 \noindent
   263 \textbf{Hints:} useful list functions: \texttt{.contains(..)} checks whether an
   264 \textbf{Hints:} useful list functions: \texttt{.contains(..)} checks
   264 element is in a list, \texttt{.flatten} turns a list of lists into just a list,
   265 whether an element is in a list, \texttt{.flatten} turns a list of
   265 \texttt{\_::\_} puts an element on the head of the list, \texttt{.head} gives you the
   266 lists into just a list, \texttt{\_::\_} puts an element on the head of
   266 first element of a list (make sure the list is not \texttt{Nil})
   267 the list, \texttt{.head} gives you the first element of a list (make
       
   268 sure the list is not \texttt{Nil}).
   267 
   269 
   268 \subsubsection*{Tasks (file knight2.scala)}
   270 \subsubsection*{Tasks (file knight2.scala)}
   269 
   271 
   270 \begin{itemize}
   272 \begin{itemize}
   271 \item[(2a)] Implement a first-function. This function takes a list of
   273 \item[(2a)] Implement a first-function. This function takes a list of
   302 \textbf{Testing} The first tour function will be called with board
   304 \textbf{Testing} The first tour function will be called with board
   303 sizes of up to $8 \times 8$.
   305 sizes of up to $8 \times 8$.
   304 \bigskip
   306 \bigskip
   305 
   307 
   306 \noindent
   308 \noindent
   307 \textbf{Hints:} a useful list function: \texttt{.filter(..)} filters a list according
   309 \textbf{Hints:} a useful list function: \texttt{.filter(..)} filters a
   308 to a boolean function; a useful option function: \texttt{.isDefined} returns true,
   310 list according to a boolean function; a useful option function:
   309 if an option is \texttt{Some(..)}; anonymous functions can be constructed using
   311 \texttt{.isDefined} returns true, if an option is \texttt{Some(..)};
   310 \texttt{(x:Int) => ...}, this functions takes an \texttt{Int} as argument
   312 anonymous functions can be constructed using \texttt{(x:Int) => ...},
       
   313 this functions takes an \texttt{Int} as an argument.
   311 
   314 
   312 
   315 
   313 \newpage
   316 \newpage
   314 \subsection*{Part 2 (3 Marks)}
   317 \subsection*{Part 2 (3 Marks)}
   315 
   318 
   368   \mbox{}\hfill[1 Mark]
   371   \mbox{}\hfill[1 Mark]
   369 \end{itemize}  
   372 \end{itemize}  
   370 \bigskip
   373 \bigskip
   371 
   374 
   372 \noindent
   375 \noindent
   373 \textbf{Hints:} a useful list function: \texttt{.sortBy} sorts a list according
   376 \textbf{Hints:} a useful list function: \texttt{.sortBy} sorts a list
   374 to a component given by the function; a function can be tested to be tail
   377 according to a component given by the function; a function can be
   375 recursive by annotation \texttt{@tailrec}, which is made available by
   378 tested to be tail recursive by annotation \texttt{@tailrec}, which is
   376 importing \texttt{scala.annotation.tailrec}
   379 made available by importing \texttt{scala.annotation.tailrec}.
   377 
   380 
   378 
   381 
   379 
   382 
   380 \end{document}
   383 \end{document}
   381 
   384