author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Sun, 13 Nov 2016 01:27:32 +0000 | |
changeset 42 | a5106bc13db6 |
parent 39 | c6fe374a5fca |
child 45 | 8399976b77fe |
permissions | -rw-r--r-- |
6 | 1 |
\documentclass{article} |
2 |
\usepackage{chessboard} |
|
3 |
\usepackage[LSBC4,T1]{fontenc} |
|
39 | 4 |
\usepackage{../style} |
6 | 5 |
|
6 |
\begin{document} |
|
7 |
||
8 |
\setchessboard{smallboard, |
|
9 |
showmover=false, |
|
10 |
boardfontencoding=LSBC4, |
|
11 |
hlabelformat=\arabic{ranklabel}, |
|
12 |
vlabelformat=\arabic{filelabel}} |
|
13 |
||
14 |
||
15 |
||
36 | 16 |
\section*{Coursework 7 (Scala, Knight's Tour)} |
6 | 17 |
|
42
a5106bc13db6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
39
diff
changeset
|
18 |
This coursework is about depth-first search in Scala and worth |
a5106bc13db6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
39
diff
changeset
|
19 |
10\%. The first part is due on 23 November at 11pm; the second, more |
a5106bc13db6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
39
diff
changeset
|
20 |
advanced part, is due on 30 November at 11pm. You are asked to |
a5106bc13db6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
39
diff
changeset
|
21 |
implement Scala programs that solve various versions of the |
a5106bc13db6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
39
diff
changeset
|
22 |
\textit{Knight's Tour Problem} on a chessboard. Make sure the files |
a5106bc13db6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
39
diff
changeset
|
23 |
you submit can be processed by just calling \texttt{scala |
a5106bc13db6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
39
diff
changeset
|
24 |
<<filename.scala>>}. |
39 | 25 |
|
26 |
\subsection*{Disclaimer} |
|
27 |
||
28 |
It should be understood that the work you submit represents |
|
29 |
your own effort. You have not copied from anyone else. An |
|
30 |
exception is the Scala code I showed during the lectures or |
|
31 |
uploaded to KEATS, which you can freely use.\bigskip |
|
32 |
||
33 |
\subsection*{Background} |
|
34 |
||
35 |
The \textit{Knight's Tour Problem} is about finding a tour such that |
|
42
a5106bc13db6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
39
diff
changeset
|
36 |
the knight visits every field on a $n\times n$ chessboard once and |
a5106bc13db6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
39
diff
changeset
|
37 |
only once. For example on a $5\times 5$ chessboard, a knight's tour is |
a5106bc13db6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
39
diff
changeset
|
38 |
as follows: |
39 | 39 |
|
6 | 40 |
|
41 |
\chessboard[maxfield=e5, |
|
42 |
pgfstyle= {[base,at={\pgfpoint{0pt}{-0.5ex}}]text}, |
|
43 |
text = \bf\small 24, markfield=a5, |
|
44 |
text = \small 11, markfield=b5, |
|
45 |
text = \small 6, markfield=c5, |
|
46 |
text = \small 17, markfield=d5, |
|
47 |
text = \small 0, markfield=e5, |
|
48 |
text = \small 19, markfield=a4, |
|
49 |
text = \small 16, markfield=b4, |
|
50 |
text = \small 23, markfield=c4, |
|
51 |
text = \small 12, markfield=d4, |
|
52 |
text = \small 7, markfield=e4, |
|
53 |
text = \small 10, markfield=a3, |
|
54 |
text = \small 5, markfield=b3, |
|
55 |
text = \small 18, markfield=c3, |
|
56 |
text = \small 1, markfield=d3, |
|
57 |
text = \small 22, markfield=e3, |
|
58 |
text = \small 15, markfield=a2, |
|
59 |
text = \small 20, markfield=b2, |
|
60 |
text = \small 3, markfield=c2, |
|
61 |
text = \small 8, markfield=d2, |
|
62 |
text = \small 13, markfield=e2, |
|
63 |
text = \small 4, markfield=a1, |
|
64 |
text = \small 9, markfield=b1, |
|
65 |
text = \small 14, markfield=c1, |
|
66 |
text = \small 21, markfield=d1, |
|
67 |
text = \small 2, markfield=e1 |
|
68 |
] |
|
69 |
||
70 |
\noindent |
|
39 | 71 |
The tour starts in the right-upper corner, then moves to field $(4,3)$, |
72 |
then $(5,1)$ and so on. There are no knight's tours on $2\times 2$, $3\times 3$ |
|
73 |
and $4\times 4$ chessboards, but for every bigger board there is. |
|
74 |
||
75 |
||
76 |
A knight's tour is called \emph{closed}, if |
|
6 | 77 |
the last step in the tour is within a knight's move to the beginning |
39 | 78 |
of the tour. So the above knight's tour is \underline{not} closed (it is |
6 | 79 |
open) because the last step on field $(1, 5)$ is not within the reach |
80 |
of the first step on $(5, 5)$. It turns out there is no closed |
|
39 | 81 |
knight's tour on a $5\times 5$ board. But there are on a $6\times |
82 |
6$ board.\bigskip |
|
6 | 83 |
|
39 | 84 |
\noindent |
85 |
If you cannot remember how a knight moved in chess, or never played |
|
86 |
chess, below are all potential moves indicated for two knights, one on |
|
87 |
field $(3, 3)$ and another on $(8, 8)$: |
|
6 | 88 |
|
89 |
||
90 |
\chessboard[color=blue!50, |
|
91 |
linewidth=0.2em, |
|
92 |
shortenstart=0.5ex, |
|
93 |
shortenend=0.5ex, |
|
94 |
markstyle=cross, |
|
95 |
markfields={b5, d5, a4, e4, a2, e2, b1, d1}, |
|
96 |
color=red!50, |
|
97 |
markfields={g6, f7}, |
|
98 |
setpieces={Nh8, Nc3}] |
|
99 |
||
100 |
||
101 |
||
102 |
||
103 |
\subsubsection*{Task} |
|
104 |
||
105 |
The task is to implement a regular expression matcher based on |
|
106 |
derivatives of regular expressions. The implementation should |
|
107 |
be able to deal with the usual (basic) regular expressions |
|
108 |
||
109 |
\noindent {\bf Important!} Your implementation should have |
|
110 |
explicit cases for the basic regular expressions, but also |
|
111 |
explicit cases for the extended regular expressions. That |
|
112 |
means do not treat the extended regular expressions by just |
|
113 |
translating them into the basic ones. See also Question 2, |
|
114 |
where you are asked to explicitly give the rules for |
|
115 |
\textit{nullable} and \textit{der} for the extended regular |
|
116 |
expressions. |
|
117 |
||
118 |
||
119 |
||
120 |
\end{document} |
|
121 |
||
122 |
%%% Local Variables: |
|
123 |
%%% mode: latex |
|
124 |
%%% TeX-master: t |
|
125 |
%%% End: |