author | Christian Urban <christian.urban@kcl.ac.uk> |
Fri, 27 Nov 2020 15:03:50 +0000 | |
changeset 374 | 90b267768329 |
parent 372 | e87462c9b895 |
child 378 | 7a5ad01a85b5 |
permissions | -rw-r--r-- |
284 | 1 |
% !TEX program = xelatex |
6 | 2 |
\documentclass{article} |
3 |
\usepackage{chessboard} |
|
4 |
\usepackage[LSBC4,T1]{fontenc} |
|
149 | 5 |
\let\clipbox\relax |
39 | 6 |
\usepackage{../style} |
213 | 7 |
\usepackage{../langs} |
166 | 8 |
\usepackage{disclaimer} |
6 | 9 |
|
10 |
\begin{document} |
|
11 |
||
12 |
\setchessboard{smallboard, |
|
45 | 13 |
zero, |
6 | 14 |
showmover=false, |
15 |
boardfontencoding=LSBC4, |
|
16 |
hlabelformat=\arabic{ranklabel}, |
|
17 |
vlabelformat=\arabic{filelabel}} |
|
18 |
||
45 | 19 |
\mbox{}\\[-18mm]\mbox{} |
6 | 20 |
|
356 | 21 |
\section*{Preliminary and Main Part 4 (Scala, 4 + 6 Marks)} |
6 | 22 |
|
265 | 23 |
\mbox{}\hfill\textit{``The problem with object-oriented languages is they’ve got all this implicit,}\\ |
24 |
\mbox{}\hfill\textit{environment that they carry around with them. You wanted a banana but}\\ |
|
25 |
\mbox{}\hfill\textit{what you got was a gorilla holding the banana and the entire jungle.''}\smallskip\\ |
|
284 | 26 |
\mbox{}\hfill\textit{ --- Joe Armstrong (creator of the Erlang programming language)}\medskip\bigskip |
265 | 27 |
|
28 |
\noindent |
|
306 | 29 |
This part is about searching and backtracking. You are asked to |
284 | 30 |
implement Scala programs that solve various versions of the |
311 | 31 |
\textit{Knight's Tour Problem} on a chessboard. The preliminary part (4\%) is |
355 | 32 |
due on \cwNINE{} at 5pm; the core part (6\%) is due on \cwNINEa{} at 5pm. |
33 |
Any 1\% you achieve in the preliminary part counts as your ``weekly engagement''. |
|
34 |
\bigskip |
|
347 | 35 |
%Note the core, more advanced, part might include material you have not |
36 |
%yet seen in the first three lectures. \bigskip |
|
50 | 37 |
|
347 | 38 |
\IMPORTANTNONE{} |
39 |
||
40 |
\noindent |
|
144 | 41 |
Also note that the running time of each part will be restricted to a |
213 | 42 |
maximum of 30 seconds on my laptop: If you calculate a result once, |
144 | 43 |
try to avoid to calculate the result again. Feel free to copy any code |
44 |
you need from files \texttt{knight1.scala}, \texttt{knight2.scala} and |
|
45 |
\texttt{knight3.scala}. |
|
39 | 46 |
|
166 | 47 |
\DISCLAIMER{} |
39 | 48 |
|
49 |
\subsection*{Background} |
|
50 |
||
51 |
The \textit{Knight's Tour Problem} is about finding a tour such that |
|
110 | 52 |
the knight visits every field on an $n\times n$ chessboard once. For |
53 |
example on a $5\times 5$ chessboard, a knight's tour is: |
|
45 | 54 |
|
55 |
\chessboard[maxfield=d4, |
|
56 |
pgfstyle= {[base,at={\pgfpoint{0pt}{-0.5ex}}]text}, |
|
57 |
text = \small 24, markfield=Z4, |
|
58 |
text = \small 11, markfield=a4, |
|
59 |
text = \small 6, markfield=b4, |
|
60 |
text = \small 17, markfield=c4, |
|
61 |
text = \small 0, markfield=d4, |
|
62 |
text = \small 19, markfield=Z3, |
|
63 |
text = \small 16, markfield=a3, |
|
64 |
text = \small 23, markfield=b3, |
|
65 |
text = \small 12, markfield=c3, |
|
66 |
text = \small 7, markfield=d3, |
|
67 |
text = \small 10, markfield=Z2, |
|
68 |
text = \small 5, markfield=a2, |
|
69 |
text = \small 18, markfield=b2, |
|
70 |
text = \small 1, markfield=c2, |
|
71 |
text = \small 22, markfield=d2, |
|
72 |
text = \small 15, markfield=Z1, |
|
73 |
text = \small 20, markfield=a1, |
|
74 |
text = \small 3, markfield=b1, |
|
75 |
text = \small 8, markfield=c1, |
|
76 |
text = \small 13, markfield=d1, |
|
77 |
text = \small 4, markfield=Z0, |
|
78 |
text = \small 9, markfield=a0, |
|
79 |
text = \small 14, markfield=b0, |
|
80 |
text = \small 21, markfield=c0, |
|
81 |
text = \small 2, markfield=d0 |
|
82 |
] |
|
144 | 83 |
|
45 | 84 |
\noindent |
212 | 85 |
This tour starts in the right-upper corner, then moves to field |
45 | 86 |
$(3,2)$, then $(4,0)$ and so on. There are no knight's tours on |
87 |
$2\times 2$, $3\times 3$ and $4\times 4$ chessboards, but for every |
|
74 | 88 |
bigger board there is. |
45 | 89 |
|
90 |
A knight's tour is called \emph{closed}, if the last step in the tour |
|
91 |
is within a knight's move to the beginning of the tour. So the above |
|
110 | 92 |
knight's tour is \underline{not} closed because the last |
45 | 93 |
step on field $(0, 4)$ is not within the reach of the first step on |
94 |
$(4, 4)$. It turns out there is no closed knight's tour on a $5\times |
|
50 | 95 |
5$ board. But there are on a $6\times 6$ board and on bigger ones, for |
96 |
example |
|
6 | 97 |
|
98 |
\chessboard[maxfield=e5, |
|
147 | 99 |
pgfstyle={[base,at={\pgfpoint{0pt}{-0.5ex}}]text}, |
45 | 100 |
text = \small 10, markfield=Z5, |
101 |
text = \small 5, markfield=a5, |
|
102 |
text = \small 18, markfield=b5, |
|
103 |
text = \small 25, markfield=c5, |
|
104 |
text = \small 16, markfield=d5, |
|
105 |
text = \small 7, markfield=e5, |
|
106 |
text = \small 31, markfield=Z4, |
|
107 |
text = \small 26, markfield=a4, |
|
108 |
text = \small 9, markfield=b4, |
|
109 |
text = \small 6, markfield=c4, |
|
110 |
text = \small 19, markfield=d4, |
|
111 |
text = \small 24, markfield=e4, |
|
112 |
% 4 11 30 17 8 15 |
|
113 |
text = \small 4, markfield=Z3, |
|
114 |
text = \small 11, markfield=a3, |
|
115 |
text = \small 30, markfield=b3, |
|
116 |
text = \small 17, markfield=c3, |
|
117 |
text = \small 8, markfield=d3, |
|
118 |
text = \small 15, markfield=e3, |
|
119 |
%29 32 27 0 23 20 |
|
120 |
text = \small 29, markfield=Z2, |
|
121 |
text = \small 32, markfield=a2, |
|
122 |
text = \small 27, markfield=b2, |
|
123 |
text = \small 0, markfield=c2, |
|
124 |
text = \small 23, markfield=d2, |
|
125 |
text = \small 20, markfield=e2, |
|
126 |
%12 3 34 21 14 1 |
|
127 |
text = \small 12, markfield=Z1, |
|
128 |
text = \small 3, markfield=a1, |
|
129 |
text = \small 34, markfield=b1, |
|
130 |
text = \small 21, markfield=c1, |
|
131 |
text = \small 14, markfield=d1, |
|
132 |
text = \small 1, markfield=e1, |
|
133 |
%33 28 13 2 35 22 |
|
134 |
text = \small 33, markfield=Z0, |
|
135 |
text = \small 28, markfield=a0, |
|
136 |
text = \small 13, markfield=b0, |
|
137 |
text = \small 2, markfield=c0, |
|
138 |
text = \small 35, markfield=d0, |
|
139 |
text = \small 22, markfield=e0, |
|
140 |
vlabel=false, |
|
141 |
hlabel=false |
|
6 | 142 |
] |
143 |
||
45 | 144 |
|
6 | 145 |
\noindent |
45 | 146 |
where the 35th move can join up again with the 0th move. |
147 |
||
48 | 148 |
If you cannot remember how a knight moves in chess, or never played |
45 | 149 |
chess, below are all potential moves indicated for two knights, one on |
48 | 150 |
field $(2, 2)$ (blue moves) and another on $(7, 7)$ (red moves): |
39 | 151 |
|
213 | 152 |
{\chessboard[maxfield=g7, |
45 | 153 |
color=blue!50, |
6 | 154 |
linewidth=0.2em, |
155 |
shortenstart=0.5ex, |
|
156 |
shortenend=0.5ex, |
|
157 |
markstyle=cross, |
|
45 | 158 |
markfields={a4, c4, Z3, d3, Z1, d1, a0, c0}, |
6 | 159 |
color=red!50, |
45 | 160 |
markfields={f5, e6}, |
213 | 161 |
setpieces={Ng7, Nb2}, |
162 |
boardfontsize=12pt,labelfontsize=9pt]} |
|
163 |
||
164 |
\subsection*{Reference Implementation} |
|
165 |
||
372 | 166 |
You\alert{} need to download \texttt{knight1.jar} from KEATS. The one |
167 |
supplied with github does not contain the correct code. See Scala coursework |
|
168 |
section. \medskip |
|
169 |
||
170 |
\noindent |
|
306 | 171 |
This Scala part comes with three reference implementations in form of |
216 | 172 |
\texttt{jar}-files. This allows you to run any test cases on your own |
213 | 173 |
computer. For example you can call Scala on the command line with the |
174 |
option \texttt{-cp knight1.jar} and then query any function from the |
|
216 | 175 |
\texttt{knight1.scala} template file. As usual you have to |
347 | 176 |
prefix the calls with \texttt{CW9a}, \texttt{CW9b} and \texttt{CW9c}. |
216 | 177 |
Since some of the calls are time sensitive, I included some timing |
178 |
information. For example |
|
213 | 179 |
|
180 |
\begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small] |
|
181 |
$ scala -cp knight1.jar |
|
347 | 182 |
scala> CW9a.enum_tours(5, List((0, 0))).length |
213 | 183 |
Time needed: 1.722 secs. |
184 |
res0: Int = 304 |
|
185 |
||
347 | 186 |
scala> CW9a.print_board(8, CW9a.first_tour(8, List((0, 0))).get) |
213 | 187 |
Time needed: 15.411 secs. |
188 |
||
189 |
51 46 55 44 53 4 21 12 |
|
190 |
56 43 52 3 22 13 24 5 |
|
191 |
47 50 45 54 25 20 11 14 |
|
192 |
42 57 2 49 40 23 6 19 |
|
193 |
35 48 41 26 61 10 15 28 |
|
194 |
58 1 36 39 32 27 18 7 |
|
195 |
37 34 31 60 9 62 29 16 |
|
196 |
0 59 38 33 30 17 8 63 |
|
197 |
\end{lstlisting}%$ |
|
198 |
||
199 |
||
200 |
\subsection*{Hints} |
|
201 |
||
202 |
\noindent |
|
307 | 203 |
\textbf{Preliminary Part} useful list functions: \texttt{.contains(..)} checks |
213 | 204 |
whether an element is in a list, \texttt{.flatten} turns a list of |
205 |
lists into just a list, \texttt{\_::\_} puts an element on the head of |
|
206 |
the list, \texttt{.head} gives you the first element of a list (make |
|
207 |
sure the list is not \texttt{Nil}); a useful option function: |
|
208 |
\texttt{.isDefined} returns true, if an option is \texttt{Some(..)}; |
|
209 |
anonymous functions can be constructed using \texttt{(x:Int) => ...}, |
|
216 | 210 |
this function takes an \texttt{Int} as an argument.\medskip |
45 | 211 |
|
212 | 212 |
|
213 |
\noindent |
|
356 | 214 |
\textbf{Main Part} a useful list function: \texttt{.sortBy} sorts a list |
212 | 215 |
according to a component given by the function; a function can be |
216 | 216 |
tested to be tail-recursive by annotation \texttt{@tailrec}, which is |
217 |
made available by importing \texttt{scala.annotation.tailrec}.\medskip |
|
212 | 218 |
|
213 | 219 |
|
220 |
||
221 |
||
296 | 222 |
\subsection*{Preliminary Part (4 Marks)} |
45 | 223 |
|
48 | 224 |
You are asked to implement the knight's tour problem such that the |
225 |
dimension of the board can be changed. Therefore most functions will |
|
50 | 226 |
take the dimension of the board as an argument. The fun with this |
60
f099bcf9cff1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
227 |
problem is that even for small chessboard dimensions it has already an |
f099bcf9cff1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
228 |
incredibly large search space---finding a tour is like finding a |
50 | 229 |
needle in a haystack. In the first task we want to see how far we get |
230 |
with exhaustively exploring the complete search space for small |
|
48 | 231 |
chessboards.\medskip |
6 | 232 |
|
48 | 233 |
\noindent |
234 |
Let us first fix the basic datastructures for the implementation. The |
|
213 | 235 |
board dimension is an integer. |
236 |
A \emph{position} (or field) on the chessboard is |
|
48 | 237 |
a pair of integers, like $(0, 0)$. A \emph{path} is a list of |
238 |
positions. The first (or 0th move) in a path is the last element in |
|
239 |
this list; and the last move in the path is the first element. For |
|
240 |
example the path for the $5\times 5$ chessboard above is represented |
|
241 |
by |
|
6 | 242 |
|
45 | 243 |
\[ |
244 |
\texttt{List($\underbrace{\texttt{(0, 4)}}_{24}$, |
|
48 | 245 |
$\underbrace{\texttt{(2, 3)}}_{23}$, ..., |
246 |
$\underbrace{\texttt{(3, 2)}}_1$, $\underbrace{\texttt{(4, 4)}}_0$)} |
|
45 | 247 |
\] |
248 |
||
249 |
\noindent |
|
250 |
Suppose the dimension of a chessboard is $n$, then a path is a |
|
251 |
\emph{tour} if the length of the path is $n \times n$, each element |
|
252 |
occurs only once in the path, and each move follows the rules of how a |
|
253 |
knight moves (see above for the rules). |
|
6 | 254 |
|
255 |
||
45 | 256 |
\subsubsection*{Tasks (file knight1.scala)} |
257 |
||
258 |
\begin{itemize} |
|
212 | 259 |
\item[(1)] Implement an \texttt{is\_legal} function that takes a |
166 | 260 |
dimension, a path and a position as arguments and tests whether the |
50 | 261 |
position is inside the board and not yet element in the |
262 |
path. \hfill[1 Mark] |
|
45 | 263 |
|
212 | 264 |
\item[(2)] Implement a \texttt{legal\_moves} function that calculates for a |
48 | 265 |
position all legal onward moves. If the onward moves are |
45 | 266 |
placed on a circle, you should produce them starting from |
145 | 267 |
``12-o'clock'' following in clockwise order. For example on an |
166 | 268 |
$8\times 8$ board for a knight at position $(2, 2)$ and otherwise |
48 | 269 |
empty board, the legal-moves function should produce the onward |
50 | 270 |
positions in this order: |
6 | 271 |
|
45 | 272 |
\begin{center} |
273 |
\texttt{List((3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4))} |
|
274 |
\end{center} |
|
275 |
||
50 | 276 |
If the board is not empty, then maybe some of the moves need to be |
277 |
filtered out from this list. For a knight on field $(7, 7)$ and an |
|
278 |
empty board, the legal moves are |
|
45 | 279 |
|
280 |
\begin{center} |
|
281 |
\texttt{List((6,5), (5,6))} |
|
48 | 282 |
\end{center} |
283 |
\mbox{}\hfill[1 Mark] |
|
45 | 284 |
|
212 | 285 |
\item[(3)] Implement two recursive functions (\texttt{count\_tours} and |
166 | 286 |
\texttt{enum\_tours}). They each take a dimension and a path as |
110 | 287 |
arguments. They exhaustively search for tours starting |
288 |
from the given path. The first function counts all possible |
|
50 | 289 |
tours (there can be none for certain board sizes) and the second |
216 | 290 |
collects all tours in a list of paths. These functions will be |
291 |
called with a path containing a single position---the starting field. |
|
292 |
They are expected to extend this path so as to find all tours starting |
|
293 |
from the given position.\\ |
|
294 |
\mbox{}\hfill[2 Marks] |
|
45 | 295 |
\end{itemize} |
6 | 296 |
|
212 | 297 |
\noindent \textbf{Test data:} For the marking, the functions in (3) |
50 | 298 |
will be called with board sizes up to $5 \times 5$. If you search |
110 | 299 |
for tours on a $5 \times 5$ board starting only from field $(0, 0)$, |
50 | 300 |
there are 304 of tours. If you try out every field of a $5 \times |
110 | 301 |
5$-board as a starting field and add up all tours, you obtain |
48 | 302 |
1728. A $6\times 6$ board is already too large to be searched |
110 | 303 |
exhaustively.\footnote{For your interest, the number of tours on |
48 | 304 |
$6\times 6$, $7\times 7$ and $8\times 8$ are 6637920, 165575218320, |
213 | 305 |
19591828170979904, respectively.}\smallskip |
148 | 306 |
|
212 | 307 |
|
296 | 308 |
\subsection*{Core Part (6 Marks)} |
45 | 309 |
|
296 | 310 |
|
311 |
\subsubsection*{Tasks (file knight1.scala cont.)} |
|
45 | 312 |
|
313 |
\begin{itemize} |
|
212 | 314 |
\item[(4)] Implement a \texttt{first}-function. This function takes a list of |
166 | 315 |
positions and a function $f$ as arguments; $f$ is the name we give to |
316 |
this argument). The function $f$ takes a position as argument and |
|
317 |
produces an optional path. So $f$'s type is \texttt{Pos => |
|
318 |
Option[Path]}. The idea behind the \texttt{first}-function is as follows: |
|
45 | 319 |
|
320 |
\[ |
|
321 |
\begin{array}{lcl} |
|
48 | 322 |
\textit{first}(\texttt{Nil}, f) & \dn & \texttt{None}\\ |
323 |
\textit{first}(x\!::\!xs, f) & \dn & \begin{cases} |
|
45 | 324 |
f(x) & \textit{if}\;f(x) \not=\texttt{None}\\ |
48 | 325 |
\textit{first}(xs, f) & \textit{otherwise}\\ |
45 | 326 |
\end{cases} |
327 |
\end{array} |
|
328 |
\] |
|
329 |
||
48 | 330 |
\noindent That is, we want to find the first position where the |
166 | 331 |
result of $f$ is not \texttt{None}, if there is one. Note that |
332 |
`inside' \texttt{first}, you do not (need to) know anything about |
|
333 |
the argument $f$ except its type, namely \texttt{Pos => |
|
213 | 334 |
Option[Path]}. If you want to find out what the result of $f$ is |
335 |
on a particular argument, say $x$, you can just write $f(x)$. |
|
336 |
There is one additional point however you should |
|
166 | 337 |
take into account when implementing \texttt{first}: you will need to |
338 |
calculate what the result of $f(x)$ is; your code should do this |
|
339 |
only \textbf{once} and for as \textbf{few} elements in the list as |
|
340 |
possible! Do not calculate $f(x)$ for all elements and then see which |
|
341 |
is the first \texttt{Some}.\\\mbox{}\hfill[1 Mark] |
|
48 | 342 |
|
212 | 343 |
\item[(5)] Implement a \texttt{first\_tour} function that uses the |
213 | 344 |
\texttt{first}-function from (4), and searches recursively for single tour. |
166 | 345 |
As there might not be such a tour at all, the \texttt{first\_tour} function |
346 |
needs to return a value of type |
|
212 | 347 |
\texttt{Option[Path]}.\\\mbox{}\hfill[1 Mark] |
48 | 348 |
\end{itemize} |
349 |
||
350 |
\noindent |
|
166 | 351 |
\textbf{Testing:} The \texttt{first\_tour} function will be called with board |
148 | 352 |
sizes of up to $8 \times 8$. |
353 |
\bigskip |
|
6 | 354 |
|
296 | 355 |
%%\newpage |
148 | 356 |
|
307 | 357 |
\noindent |
296 | 358 |
As you should have seen in the earlier parts, a naive search for tours beyond |
145 | 359 |
$8 \times 8$ boards and also searching for closed tours even on small |
329 | 360 |
boards takes too much time. There is a heuristics, called \emph{Warnsdorf's |
361 |
Rule} that can speed up finding a tour. This heuristics states that a |
|
145 | 362 |
knight is moved so that it always proceeds to the field from which the |
48 | 363 |
knight will have the \underline{fewest} onward moves. For example for |
364 |
a knight on field $(1, 3)$, the field $(0, 1)$ has the fewest possible |
|
365 |
onward moves, namely 2. |
|
45 | 366 |
|
367 |
\chessboard[maxfield=g7, |
|
368 |
pgfstyle= {[base,at={\pgfpoint{0pt}{-0.5ex}}]text}, |
|
369 |
text = \small 3, markfield=Z5, |
|
370 |
text = \small 7, markfield=b5, |
|
371 |
text = \small 7, markfield=c4, |
|
372 |
text = \small 7, markfield=c2, |
|
373 |
text = \small 5, markfield=b1, |
|
374 |
text = \small 2, markfield=Z1, |
|
375 |
setpieces={Na3}] |
|
376 |
||
377 |
\noindent |
|
166 | 378 |
Warnsdorf's Rule states that the moves on the board above should be |
50 | 379 |
tried in the order |
45 | 380 |
|
381 |
\[ |
|
46 | 382 |
(0, 1), (0, 5), (2, 1), (2, 5), (3, 4), (3, 2) |
45 | 383 |
\] |
384 |
||
46 | 385 |
\noindent |
60
f099bcf9cff1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
386 |
Whenever there are ties, the corresponding onward moves can be in any |
45 | 387 |
order. When calculating the number of onward moves for each field, we |
388 |
do not count moves that revisit any field already visited. |
|
389 |
||
213 | 390 |
\subsubsection*{Tasks (file knight2.scala)} |
45 | 391 |
|
392 |
\begin{itemize} |
|
212 | 393 |
\item[(6)] Write a function \texttt{ordered\_moves} that calculates a list of |
216 | 394 |
onward moves like in (2) but orders them according to |
166 | 395 |
Warnsdorf’s Rule. That means moves with the fewest legal onward moves |
86 | 396 |
should come first (in order to be tried out first). \hfill[1 Mark] |
50 | 397 |
|
329 | 398 |
\item[(7)] Implement a \texttt{first\_closed\_tour\_heuristics} |
213 | 399 |
function that searches for a single |
400 |
\textbf{closed} tour on a $6\times 6$ board. It should try out |
|
401 |
onward moves according to |
|
402 |
the \texttt{ordered\_moves} function from (6). It is more likely to find |
|
50 | 403 |
a solution when started in the middle of the board (that is |
86 | 404 |
position $(dimension / 2, dimension / 2)$). \hfill[1 Mark] |
45 | 405 |
|
329 | 406 |
\item[(8)] Implement a \texttt{first\_tour\_heuristics} function |
166 | 407 |
for boards up to |
213 | 408 |
$30\times 30$. It is the same function as in (7) but searches for |
409 |
tours (not just closed tours). It might be called with any field on the |
|
216 | 410 |
board as starting field.\\ |
213 | 411 |
%You have to be careful to write a |
329 | 412 |
%tail-recursive function of the \texttt{first\_tour\_heuristics} function |
213 | 413 |
%otherwise you will get problems with stack-overflows.\\ |
414 |
\mbox{}\hfill[1 Mark] |
|
415 |
\end{itemize} |
|
416 |
||
417 |
\subsubsection*{Task (file knight3.scala)} |
|
418 |
\begin{itemize} |
|
419 |
\item[(9)] Implement a function \texttt{tour\_on\_mega\_board} which is |
|
216 | 420 |
the same function as in (8), \textbf{but} should be able to |
421 |
deal with boards up to |
|
422 |
$70\times 70$ \textbf{within 30 seconds} (on my laptop). This will be tested |
|
213 | 423 |
by starting from field $(0, 0)$. You have to be careful to |
424 |
write a tail-recursive function otherwise you will get problems |
|
425 |
with stack-overflows. Please observe the requirements about |
|
426 |
the submissions: no tricks involving \textbf{.par}.\medskip |
|
427 |
||
216 | 428 |
The timelimit of 30 seconds is with respect to the laptop on which the |
429 |
marking will happen. You can roughly estimate how well your |
|
213 | 430 |
implementation performs by running \texttt{knight3.jar} on your |
216 | 431 |
computer. For example the reference implementation shows |
432 |
on my laptop: |
|
213 | 433 |
|
434 |
\begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small] |
|
435 |
$ scala -cp knight3.jar |
|
436 |
||
347 | 437 |
scala> CW9c.tour_on_mega_board(70, List((0, 0))) |
213 | 438 |
Time needed: 9.484 secs. |
439 |
...<<long_list>>... |
|
440 |
\end{lstlisting}%$ |
|
441 |
||
145 | 442 |
\mbox{}\hfill[1 Mark] |
45 | 443 |
\end{itemize} |
148 | 444 |
\bigskip |
445 |
||
446 |
||
447 |
||
6 | 448 |
|
449 |
\end{document} |
|
450 |
||
451 |
%%% Local Variables: |
|
452 |
%%% mode: latex |
|
453 |
%%% TeX-master: t |
|
454 |
%%% End: |