diff -r 2969ee4a6cee -r ca9c1cf929fa slides/slides04.tex --- a/slides/slides04.tex Fri Nov 22 17:01:55 2019 +0000 +++ b/slides/slides04.tex Tue Nov 26 01:22:36 2019 +0000 @@ -1,3 +1,4 @@ +% !TEX program = xelatex \documentclass[dvipsnames,14pt,t,xelatex]{beamer} \usepackage{../slides} \usepackage{../graphics} @@ -145,9 +146,11 @@ \begin{center} \begin{tabular}{ll} Email: & christian.urban at kcl.ac.uk\\ - Office: & N\liningnums{7.07} (North Wing, Bush House)\\ - Slides \& Code: & KEATS\medskip\\ - Office Hours: & Mondays 12:00 -- 14:00\\ + Office: & N\liningnums{7.07} (North Wing, Bush House)\bigskip\\ + Slides \& Code: & KEATS\\ + & \onslide<2>{\alert{A Crash-Course in Scala}}\bigskip\\ + Office Hours: & Thursdays 12:00 -- 14:00\\ + Additionally: & (for Scala) Tuesdays 10:45 -- 11:45\\ \end{tabular} \end{center} @@ -155,88 +158,54 @@ \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[c] -\frametitle{Somewhere Remote} - -\begin{center} -\includegraphics[scale=0.37]{../pics/sahara.jpg} -\end{center} - -\end{frame} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\frametitle{Hints in CW} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -\begin{frame}[t] -\frametitle{This is a bit harsh\ldots} - -\mbox{}\\[-22mm]\mbox{} - -\begin{center} -\begin{bubble}[10.5cm] - ...trying a new method because the fucking github reports dont tell me - which test failed. It's not really helpful when the inline tests work - and it compiles but all i get is 'one test failed'... really helpful my dude. -\end{bubble} +\begin{center} +\includegraphics[scale=0.4]{../pics/hints.png} \end{center} -\begin{center} -\begin{bubble}[10.5cm] - ...Reverted back and finished part 5, this is ridiculous how one test works - and all I get is 'ONE TEST FAILED'. Fix your reports before giving us - assignments like this... -\end{bubble} -\end{center} +\small +\begin{itemize} + \item Scala Library, e.g.~\texttt{span} in \\ + \url{https://www.scala-lang.org/api/current/scala/collection/immutable/List.html} +\end{itemize} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + -\end{frame} - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -\begin{frame}[t,fragile] -\frametitle{Needless to say I tried it out} - -\mbox{}\\[-7mm]\mbox{}\footnotesize +\begin{frame}[c] +\frametitle{Preliminary 7} -\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-4mm] -> legal_moves(8, Nil, (2,2)) - = List((3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4)) - -> legal_moves(8, Nil, (7,7)) - = List((6,5), (5,6)) +Raw marks (261 submissions):\bigskip -> legal_moves(8, List((4,1), (1,0)), (2,2)) - = List((3,4), (4,3), (3,0), (0,1), (0,3), (1,4)) - -> legal_moves(1, Nil, (0,0)) - = List((-1,-2), (-2,-1)) +\begin{itemize} +\item 4\%: \hspace{4mm}236 +\item 3\%: \hspace{4mm}10 +\item 2\%: \hspace{4mm}1 +\item 1\%: \hspace{4mm}0 +\item 0\%: \hspace{4mm}15 +\end{itemize}\bigskip\bigskip -> legal_moves(2, Nil, (0,0)) - = List((1,-2), (-1,-2), (-2,-1), (-2,1)) - -> legal_moves(3, Nil, (0,0)) - = List((1,2), (2,1), (2,-1), (1,-2), (-1,-2), (-2,-1), (-2,1), (-1,2)) -\end{lstlisting} - -\LEFTarrow{1}{9}{9} -\LEFTarrow{1}{12}{11} -\DOWNarrow{1}{10}{13} +\footnotesize +(interviews ongoing!) \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[c,fragile] \small -\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-7mm] -def is_legal(dim: Int, p: Path, x: Pos): Boolean = { - if (......some_really_long_condition.....) false +\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=1mm] +def is_legal(dim: Int, p: Path, x: Pos) = { + if (...some_really_long_condition...) false else true } \end{lstlisting} @@ -246,16 +215,130 @@ \rule{11cm}{0.3mm} \bigskip +\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=1mm] +def is_legal(dim: Int, p: Path, x: Pos) = + !(...some_really_long_condition...) +\end{lstlisting} + +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame}[c,fragile] +\small + +\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=1mm] +def foobar(...) = { + val cs = for (c <- str) yield c.toLowerCase + ... +} +\end{lstlisting} + +\pause +\bigskip +\rule{11cm}{0.3mm} +\bigskip + +\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=1mm] +def foobar(...) = { + val cs = str.map(_.toLowerCase) + ... +} +\end{lstlisting} + +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame}[c,fragile] +\small + \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-7mm] -def is_legal(dim: Int, p: Path, x: Pos): Boolean = - !......some_really_long_condition..... -\end{lstlisting}\pause - +def RomanNumeral2Int(rs: RomanNumeral): Int = + rs match { + case Nil => 0 + case M::r => 1000 + RomanNumeral2Int(r) + case C::M::r => 900 + RomanNumeral2Int(r) + case D::r => 500 + RomanNumeral2Int(r) + case C::D::r => 400 + RomanNumeral2Int(r) + case C::r => 100 + RomanNumeral2Int(r) + case X::C::r => 90 + RomanNumeral2Int(r) + case L::r => 50 + RomanNumeral2Int(r) + case X::L::r => 40 + RomanNumeral2Int(r) + case X::r => 10 + RomanNumeral2Int(r) + case I::X::r => 9 + RomanNumeral2Int(r) + case V::r => 5 + RomanNumeral2Int(r) + case I::V::r => 4 + RomanNumeral2Int(r) + case I::r => 1 + RomanNumeral2Int(r) + } +\end{lstlisting} \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame}[c,fragile] +\frametitle{Last Week: Pattern Matching} +\small + +\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=3mm] +def fizz_buzz(n: Int) : String = + (n % 3, n % 5) match { + case (0, 0) => "fizz buzz" + case (0, _) => "fizz" + case (_, 0) => "buzz" + case _ => n.toString + } +\end{lstlisting} + +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame}[c,fragile] +\frametitle{Reverse Polish Notation} + +{\Large\bl{$(3 + 1) * (2 + 9)$}}\bigskip + +{\Large$\Rightarrow$}\bigskip + +{\;\;\Large\bl{$3\;\;1\;+\;2\;\;9\;+\;*$}} + +\begin{textblock}{3}(11,4) +\begin{onlyenv}<2> +\begin{lstlisting}[language=JVMIS] +ldc 3 +ldc 1 +iadd +ldc 2 +ldc 9 +iadd +imul +\end{lstlisting} +\end{onlyenv} +\end{textblock} + +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame}[c,fragile] +\frametitle{Sudoku} + +A very simple-minded version on 110 problems:\bigskip + +\begin{itemize} +\item 1 core: 800 secs +\item 2 cores: 400 secs +\item 8 cores: 290 secs +\item 18 cores: 142 secs +\end{itemize} + +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[c] \frametitle{DFAs} @@ -349,12 +432,50 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[t] + + \begin{center} + \includegraphics[scale=0.3]{../pics/blow.png} + \end{center} + + \begin{textblock}{14}(2,11.4) + \large\bf{}Mind-Blowing Regular Expressions:\\ + \centering in Python, JavaScript, Java + \end{textblock} +\end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\begin{frame}[c] - \frametitle{CW\liningnums{9} (\liningnums{1} Part): Regexes} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame}[c,fragile] +\frametitle{Regular Expressions} + +Suppose you have a regular expression +\only<1-3>{\alert{\texttt{(a*)b}}}% +\only<4->{\alert{\texttt{(a*)*b}}} :\bigskip + +\begin{center} +\only<1>{\code{"aaaaaaaaaaaaaaab"}} +\only<2>{\code{"aaaaa...........aaaaaaaaaaaaaaaaaaaab"}} +\only<3>{\code{"aaaaa...........aaaaaaaaaaaaaaaaaaaa"}} +\only<4>{\code{"aaaaa...........aaaaaaaaaaaaaaaaaaaab"}} +\only<5->{\code{"aaaaa...........aaaaaaaaaaaaaaaaaaaa"}} +\end{center} + +\only<6>{ +\begin{textblock}{13}(5,12) +How long does Python need to find out? +\end{textblock}} + +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame}<1>[c] + \frametitle{CW 9: Regexes} \begin{center} - Graphs: $(a^*)^* b$ and strings $\underbrace{\;a\ldots a\;}_{n}$\bigskip + Graphs: \alert{\texttt{(a*)*b}} and strings $\underbrace{\;\texttt{a}\ldots \texttt{a}\;}_{n}$\bigskip \begin{tabular}[t]{@{\hspace{-8mm}}c@{\hspace{-4mm}}c@{}} \only<1>{\raisebox{6mm}{\begin{tikzpicture} @@ -421,26 +542,43 @@ \hfill\small\url{https://vimeo.com/112065252} \end{frame} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[c] -\frametitle{Hint} \begin{center} -\LARGE\textbf{\alert{Pattern-Matching}} + \includegraphics[angle=90,scale=0.35]{/Users/cu/vote.pdf} \end{center} \end{frame} - +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame}[c] + +\begin{center} + \includegraphics[scale=0.25]{/Users/cu/dresden.png} +\end{center} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\begin{frame}[c,fragile] -\frametitle{\alert{Questions?}} +\begin{textblock}{13}(2,12) +\includegraphics[scale=0.08]{/Users/cu/kiss.jpg} +\end{textblock} + +\begin{textblock}{13}(6.8,12) +\includegraphics[scale=0.079]{/Users/cu/pioniere.jpg} +\end{textblock} + +\begin{textblock}{13}(11,12) +\includegraphics[scale=0.20]{/Users/cu/iron.jpg} +\end{textblock} + +\DOWNarrow{1}{11}{8.6} \end{frame} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +