Binary file cws/cw02.pdf has changed
--- a/cws/cw02.tex Fri Nov 17 02:13:40 2017 +0000
+++ b/cws/cw02.tex Fri Nov 17 09:13:03 2017 +0000
@@ -257,7 +257,13 @@
1728. A $6\times 6$ board is already too large to be searched
exhaustively.\footnote{For your interest, the number of tours on
$6\times 6$, $7\times 7$ and $8\times 8$ are 6637920, 165575218320,
- 19591828170979904, respectively.}
+ 19591828170979904, respectively.}\bigskip
+
+\noindent
+\textbf{Hints:} useful list functions: \texttt{.contains(..)} checks whether an
+element is in a list, \texttt{.flatten} turns a list of lists into just a list,
+\texttt{\_::\_} puts an element on the head of the list, \texttt{.head} gives you the
+first element of a list (make sure the list is not \texttt{Nil})
\subsubsection*{Tasks (file knight2.scala)}
@@ -294,9 +300,17 @@
\noindent
\textbf{Testing} The first tour function will be called with board
-sizes of up to $8 \times 8$.
+sizes of up to $8 \times 8$.
+\bigskip
-%%\newpage
+\noindent
+\textbf{Hints:} a useful list function: \texttt{.filter(..)} filters a list according
+to a boolean function; a useful option function: \texttt{.isDefined} returns true,
+if an option is \texttt{Some(..)}; anonymous functions can be constructed using
+\texttt{(x:Int) => ...}, this functions takes an \texttt{Int} as argument
+
+
+\newpage
\subsection*{Part 2 (3 Marks)}
As you should have seen in Part 1, a naive search for tours beyond
@@ -353,6 +367,15 @@
otherwise you will get problems with stack-overflows.\\
\mbox{}\hfill[1 Mark]
\end{itemize}
+\bigskip
+
+\noindent
+\textbf{Hints:} a useful list function: \texttt{.sortBy} sorts a list according
+to a component given by the function; a function can be tested to be tail
+recursive by annotation \texttt{@tailrec}, which is made available by
+importing \texttt{scala.annotation.tailrec}
+
+
\end{document}
Binary file pics/hoare.jpg has changed
--- a/progs/lecture1.scala Fri Nov 17 02:13:40 2017 +0000
+++ b/progs/lecture1.scala Fri Nov 17 09:13:03 2017 +0000
@@ -259,7 +259,9 @@
m <- (1 to 3).toList;
if (n + m) % 2 == 0) yield (n, m)
-
+for (n <- (1 to 3).toList;
+ m <- (1 to 3).toList;
+ if ((n + m) % 2 == 0)) yield (n, m)
// with patterns
--- a/progs/lecture2.scala Fri Nov 17 02:13:40 2017 +0000
+++ b/progs/lecture2.scala Fri Nov 17 09:13:03 2017 +0000
@@ -2,7 +2,7 @@
//=================
-// Overloaded math operations
+// the pain with overloaded math operations
(100 / 4)
@@ -265,6 +265,17 @@
// ...
+// an aside: partial application
+
+def add(a: Int)(b: Int) : Int = a + b
+
+sum(add(2), 0, 2)
+sum(add(10), 0, 2)
+
+def add2(a: Int, b: Int) : Int = a + b
+sum(x => add2(2, x), 0, 2)
+sum(x => add2(10, x), 0, 2)
+
// Function Composition
//======================
@@ -312,14 +323,6 @@
-// Type abbreviations
-//====================
-
-// some syntactic convenience
-
-type Pos = (int, Int)
-type Board = List[List[Int]]
-
// Implicits (Cool Feature)
@@ -530,6 +533,14 @@
time_needed(10, count_intersection2(A, B))
+// Type abbreviations
+//====================
+
+// some syntactic convenience
+
+type Pos = (int, Int)
+type Board = List[List[Int]]
+
Binary file slides/slides02.pdf has changed
--- a/slides/slides02.tex Fri Nov 17 02:13:40 2017 +0000
+++ b/slides/slides02.tex Fri Nov 17 09:13:03 2017 +0000
@@ -2,7 +2,9 @@
\usepackage{../slides}
\usepackage{../graphics}
\usepackage{../langs}
-%\usepackage{../data}
+\usepackage{chessboard}
+\usepackage[LSBC4,T1]{fontenc}
+% \usepackage{../data}
\hfuzz=220pt
@@ -193,7 +195,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[t]
-\frametitle{\begin{tabular}{c}Why Scala?\end{tabular}}
+\frametitle{Why Scala? No null!}
\begin{itemize}
@@ -217,55 +219,35 @@
\end{bubble}
\end{textblock}
-\begin{textblock}{5}(11.8,1)
-%%\includegraphics[scale=0.20]{hoare.jpg}\\
+\begin{textblock}{5}(12.5,1.9)
+\includegraphics[scale=0.05]{../pics/hoare.jpg}\\
\end{textblock}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\begin{frame}[c]
-\frametitle{Types}
-
-\begin{itemize}
-\item Base types\smallskip
-
- \begin{tabular}{@{}l@{}}
- \textcolor{codegreen}{\texttt{Int}},
- \textcolor{codegreen}{\texttt{Long}},
- \textcolor{codegreen}{\texttt{BigInt}},
- \textcolor{codegreen}{\texttt{Float}},
- \textcolor{codegreen}{\texttt{Double}}\\
- \textcolor{codegreen}{\texttt{String}},
- \textcolor{codegreen}{\texttt{Char}}\\
- \textcolor{codegreen}{\texttt{Boolean}}
- \end{tabular}
-
-\item Compound types \smallskip
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{frame}[c,fragile]
+\frametitle{\begin{tabular}{c}\\[1cm]\alert{Questions?}\end{tabular}}
- \begin{tabular}{@{}ll@{}}
- \textcolor{codegreen}{\texttt{List[Int]}} & lists of Int's \\
- \textcolor{codegreen}{\texttt{Set[Double]}} & sets of Double's \\
- \textcolor{codegreen}{\texttt{(Int, String)}} & Int-String pair\\
- \textcolor{codegreen}{\texttt{List[(BigInt, String)]}} &
- lists of BigInt-String\\
- & pairs\\
- \textcolor{codegreen}{\texttt{List[List[Int]]}} & list of lists of Int's\\
- \end{tabular}
-
-\end{itemize}
-
-\end{frame}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\begin{frame}[c]
-\frametitle{\begin{tabular}{c}\\[3cm]\alert{Questions?}\end{tabular}}
-
-\mbox{}
+\begin{center}
+\chessboard[maxfield=g7,
+ color=blue!50,
+ linewidth=0.2em,
+ shortenstart=0.5ex,
+ shortenend=0.5ex,
+ markstyle=cross,
+ markfields={a4, c4, Z3, d3, Z1, d1, a0, c0},
+ color=red!50,
+ markfields={f5, e6},
+ boardfontsize=12pt,labelfontsize=8pt,
+ setpieces={Ng7, Nb2},showmover=false]
+\end{center}
+
+\begin{center}
+My Scala Office Hours: Thursdays 11 -- 13
+\end{center}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}