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