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