updated
authorChristian Urban <urbanc@in.tum.de>
Thu, 01 Dec 2016 17:08:02 +0000
changeset 79 2d57b0d43a0f
parent 78 85f2f75abeeb
child 80 ea0d0a862a9c
updated
cws/cw01.pdf
cws/cw01.tex
cws/cw02.pdf
cws/cw02.tex
cws/cw03.pdf
cws/cw03.tex
Binary file cws/cw01.pdf has changed
--- a/cws/cw01.tex	Wed Nov 30 10:07:05 2016 +0000
+++ b/cws/cw01.tex	Thu Dec 01 17:08:02 2016 +0000
@@ -12,7 +12,16 @@
 processing and recursion. The third part is more advanced and might
 include material you have not yet seen in the first lecture.
 Make sure the files you submit can be processed by just calling
-\texttt{scala <<filename.scala>>}. 
+\texttt{scala <<filename.scala>>}.\bigskip
+
+\noindent
+\textbf{Important:} Do not use any mutable data structures in your
+submissions! They are not needed. This excludes the use of
+\texttt{ListBuffer}s, for example. Do not use \texttt{return} in your
+code! It has a different meaning in Scala, than in Java.
+Do not use \texttt{var}! This declares a mutable variable. Make sure the
+functions you submit are defined on the ``top-level'' of Scala, not
+inside a class or object. 
 
 
 \subsection*{Disclaimer}
@@ -195,7 +204,7 @@
 Since the question about Mr Drumb's business acumen remains, let's do a
 quick back-of-the-envelope calculation in Scala whether his claim has
 any merit. Let's suppose we are given \$100 in 1978 and we follow a
-really dump investment strategy, namely:
+really dumb investment strategy, namely:
 
 \begin{itemize}
 \item We blindly choose a portfolio of stocks, say some Blue-Chip stocks
Binary file cws/cw02.pdf has changed
--- a/cws/cw02.tex	Wed Nov 30 10:07:05 2016 +0000
+++ b/cws/cw02.tex	Thu Dec 01 17:08:02 2016 +0000
@@ -20,9 +20,10 @@
 backtracking. The first part is due on 23 November at 11pm; the
 second, more advanced part, is due on 30 November at 11pm. You are
 asked to implement Scala programs that solve various versions of the
-\textit{Knight's Tour Problem} on a chessboard. Make sure the files
-you submit can be processed by just calling \texttt{scala
-  <<filename.scala>>}.\bigskip
+\textit{Knight's Tour Problem} on a chessboard. Note the second part
+might include material you have not yet seen in the first two
+lectures.  Make sure the files you submit can be processed by just
+calling \texttt{scala <<filename.scala>>}.\bigskip
 
 \noindent
 \textbf{Important:} Do not use any mutable data structures in your
@@ -260,12 +261,17 @@
   \]
 
   \noindent That is, we want to find the first position where the
-  result of $f$ is not \texttt{None}, if there is one.\mbox{}\hfill[1 Mark]
+  result of $f$ is not \texttt{None}, if there is one. Note that you
+  do not (need to) know anything about the function $f$ except its
+  type, namely \texttt{Pos => Option[Path]}. There is one additional
+  point however you should take into account when implementing
+  \textit{first}: you will need to calculate what the result of $f(x)$
+  is; your code should do this only \textbf{once}!\\\mbox{}\hfill[1 Mark]
   
 \item[(2b)] Implement a first-tour function that uses the
   first-function from (2a), and searches recursively for an open tour.
   As there might not be such a tour at all, the first-tour function
-  needs to return an \texttt{Option[Path]}.\hfill[2 Marks]
+  needs to return an \texttt{Option[Path]}.\\\mbox{}\hfill[2 Marks]
 \end{itemize}
 
 \noindent
Binary file cws/cw03.pdf has changed
--- a/cws/cw03.tex	Wed Nov 30 10:07:05 2016 +0000
+++ b/cws/cw03.tex	Thu Dec 01 17:08:02 2016 +0000
@@ -6,12 +6,12 @@
 
 \section*{Coursework 8 (Scala, Regular Expressions}
 
-This coursework is worth 10\%. It is about regular expressions and
-pattern matching. The first part is due on 30 November at 11pm; the
-second, more advanced part, is due on 7 December at 11pm. You are
-asked to implement a regular expression matcher. Make sure the files
-you submit can be processed by just calling \texttt{scala
-  <<filename.scala>>}.\bigskip
+This coursework is worth 10\%. It is about regular expressions,
+pattern matching and polymorphism. The first part is due on 30
+November at 11pm; the second, more advanced part, is due on 7 December
+at 11pm. You are asked to implement a regular expression matcher. Make
+sure the files you submit can be processed by just calling
+\texttt{scala <<filename.scala>>}.\bigskip
 
 \noindent
 \textbf{Important:} Do not use any mutable data structures in your
@@ -65,7 +65,7 @@
 \item[$\bullet$] \url{http://davidvgalbraith.com/how-i-fixed-atom/}  
 \end{itemize}}
 
-\subsection*{Tasks (file re.scala)}
+\subsubsection*{Tasks (file re.scala)}
 
 \begin{itemize}
 \item[(1a)] Implement a function, called \textit{nullable}, by recursion over
@@ -159,8 +159,17 @@
   For example the regular expression
   \[(r_1 + \ZERO) \cdot \ONE + ((\ONE + r_2) + r_3) \cdot (r_4 \cdot \ZERO)\]
 
-  simplifies to just $r_1$. 
-  \hfill[1 Mark]
+  simplifies to just $r_1$. \textbf{Hints:} Regular expressions can be
+  seen as trees and there are several methods for traversing
+  trees. One of them corresponds to the inside-out traversal. Also
+  remember numerical expressions from school: there you had exprssions
+  like $u + \ldots + (1 \cdot x) * \ldots (z + (y \cdot 0)) \ldots$
+  and simplification rules that looked very similar to rules
+  above. You would simplify such numerical expressions by replacing
+  for example the $y \cdot 0$ by $0$, or $1\cdot x$ by $x$, and then
+  look if more rules are applicable. If you organise this
+  simplification in an inside-out fashion, it is always clear which
+  rule should applied next.\\\mbox{}\hfill[1 Mark]
 
 \item[(1d)] Implement two functions: The first, called \textit{ders},
   takes a list of characters and a regular expression as arguments, and
@@ -215,7 +224,7 @@
 give you another method and datapoints for testing the \textit{der}
 and \textit{simp} functions from Part~1.
 
-\subsection*{Tasks (file re2.scala)}
+\subsubsection*{Tasks (file re2.scala)}
 
 \begin{itemize}
 \item[(2a)] Write a \textbf{polymorphic} function, called
@@ -240,7 +249,7 @@
 
   Make sure you write a \textbf{tail-recursive} version of
   \textit{iterT}.  If you add the annotation \texttt{@tailrec} (see
-  below) you should not get an error message.
+  below) your code should not produce an error message.
 
   \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]  
   import scala.annotation.tailrec
@@ -253,7 +262,8 @@
   integers $0 \le n$. Given the type variable \texttt{A}, the type of
   $f$ is \texttt{A => A} and the type of $x$ is \texttt{A}. This means
   \textit{iterT} can be used, for example, for functions from integers
-  to integers, or strings to strings.  \\ \mbox{}\hfill[2 Marks]
+  to integers, or strings to strings, or regular expressions to
+  regular expressions.  \\ \mbox{}\hfill[2 Marks]
 
 \item[(2b)] Implement a function, called \textit{size}, by recursion
   over regular expressions. If a regular expression is seen as a tree,
@@ -273,7 +283,7 @@
 
 You can use \textit{size} and \textit{iterT} in order to test how much
 the 'evil' regular expression $(a^*)^* \cdot b$ grows when taking
-successive derivatives according the letter $a$ and compare it to
+successive derivatives according the letter $a$ and then compare it to
 taking the derivative, but simlifying the derivative after each step.
 For example, the calls
 
@@ -283,7 +293,8 @@
   \end{lstlisting}
 
   produce without simplification a regular expression of size of
-  7340068 for the derivative after 20 iterations, while the latter is
+  7340068 after 20 iterations, while the one with
+  simplification gives
   just 8.\\ \mbox{}\hfill[1 Mark]