slides/slides03.tex
changeset 217 e689375abcc1
parent 158 94b11ac19b41
child 218 22705d22c105
--- a/slides/slides03.tex	Thu Nov 22 23:00:57 2018 +0000
+++ b/slides/slides03.tex	Fri Nov 23 01:52:37 2018 +0000
@@ -21,58 +21,6 @@
 % beamer stuff 
 \renewcommand{\slidecaption}{PEP (Scala) 03, King's College London}
 
-\begin{filecontents}{re3a.data}
-1 0.00003
-500001 0.22527
-1000001 0.62752
-1500001 0.88485
-2000001 1.39815
-2500001 1.68619
-3000001 1.94957
-3500001 2.15878
-4000001 2.59918
-4500001 5.90679
-5000001 13.11295
-5500001 19.15376
-6000001 40.16373
-\end{filecontents}
-\begin{filecontents}{re-python2.data}
-1 0.033
-5 0.036
-10 0.034
-15 0.036
-18 0.059
-19 0.084
-20 0.141
-21 0.248
-22 0.485
-23 0.878
-24 1.71
-25 3.40
-26 7.08
-27 14.12
-28 26.69
-\end{filecontents}
-
-\begin{filecontents}{re-java.data}
-5  0.00298
-10  0.00418
-15  0.00996
-16  0.01710
-17  0.03492
-18  0.03303
-19  0.05084
-20  0.10177
-21  0.19960
-22  0.41159
-23  0.82234
-24  1.70251
-25  3.36112
-26  6.63998
-27  13.35120
-28  29.81185
-\end{filecontents}
-
 \begin{document}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \begin{frame}[t]
@@ -88,8 +36,7 @@
     Email:  & christian.urban at kcl.ac.uk\\
     Office: & N7.07 (North Wing, Bush House)\\
     Slides \& Code: & KEATS\medskip\\
-    Scala Office & \\
-    Hours: &  Thursdays 11 -- 13\\
+    Office Hours: &  \alert{next Monday} 11 -- 12 \& 13 -- 14\\
   \end{tabular}
   \end{center}
 
@@ -97,36 +44,66 @@
 \end{frame}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
+
+\begin{frame}[c]
+\frametitle{Marks for CW6 (Part 1 + 2)}
+
+Raw marks (234 submissions):
+
+\begin{itemize}
+\item 6\%: \hspace{4mm}163 students
+\item 5\%: \hspace{4mm}29
+\item 4\%: \hspace{4mm}3
+\item 3\%: \hspace{4mm}13
+\item 2\%: \hspace{4mm}3
+\item 1\%: \hspace{4mm}0
+\item 0\%: \hspace{4mm}23 
+\end{itemize}  
+\end{frame}
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \begin{frame}[c,fragile]
 
-\begin{textblock}{6}(0.5,0.5)
-\begin{bubble}[11.5cm]
-\footnotesize
 \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
-import java.util.concurrent._
-import java.util.concurrent.atomic._
+def collatz(n: Long) : Long =
+  {
+    val toReturn = collatzHelper(n, 0)
+    toReturn
+  } 
+\end{lstlisting}
+
+\pause
+\bigskip
+\rule{11cm}{0.3mm}
+\bigskip
 
-  def collatz(input:Int){
-          CollatzConjecture(input);
-          println(count.get());
-      }
-      def collatz_max(input:Int){
-          val List = new Array[Int](input)
-            for (i <- 0 to input-1){
-                CollaĵConjecture(i);
-                List(i)=count.get();
-                count.set(0);
-            }
-            val max = new AtomicInteger();
-            max.set(List(0));
-            val index = new AtomicInteger();
-            index.set(1);
- 
-\end{lstlisting}
-\end{bubble}
-\end{textblock}
+\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
+def collatz(n: Long) : Long =
+  collatzHelper(n, 0)
+\end{lstlisting}\pause
+
+
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{frame}[c,fragile]
+
+\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
+def collatz_max(bnd: Long) : (Long,Long) = {val lst = for(a<-(1 to bnd.toInt)) yield (collatz(a),a.toLong);val lst2 = lst.sortBy(_._1);lst2(lst2.length-1)}
+\end{lstlisting}\bigskip
+
+\tiny
+\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
+def collatz_max(bnd: Long) : (Long,Long) = {val lst = for(a<-(1 to bnd.toInt)) yield (collatz(a),a.toLong);val lst2 = lst.sortBy(_._1);lst2(lst2.length-1)}
+\end{lstlisting}\pause
+
 
 \end{frame}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
@@ -134,186 +111,109 @@
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \begin{frame}[c,fragile]
 
-\begin{textblock}{6}(0.5,0.5)
-\begin{bubble}[11.5cm]
-\footnotesize
-\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
-             for(i<-0 to input-1){
-                val temp :Int=max.get();
-                if (temp < List(i)){
-                    max.set(List(i));
-                    index.set(i);
-                }
-            }
-            println("("+max.get() +","+ index.get()+ ")");
-      }
+\small
+\begin{lstlisting}[language=Scala, xleftmargin=-4mm,numbers=left]
+ def process_ratings(lines: List[String]) = {
+    val values = List[(String,String)]()
+
+    for(line <- lines){
+        val splitList = line.split(",").toList
 
-      def CollatzConjecture(n: Long): Long = {
-        count.incrementAndGet();
-        if (n <= 1)
-            1
-        else if (n\%2 ==0)
-            CollatzConjecture(n/2);
-            else
-               CollatzConjecture((3*n)+1);
-   }
+        if(splitList(2).toInt >= 4){
+            val userID = splitList(0)
+            val movieID = splitList(1)
+            val tuple = (userID, movieID)
+            tuple :: values
+        }
+    }
+    
+    values
  }
 \end{lstlisting}
-\end{bubble}
-\end{textblock}
+
+\normalsize
+What does this function always return?
+
 
 \end{frame}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 
-
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\begin{frame}[c]
-  \frametitle{CW3 (1 Part): Regexes}
-  
-\begin{center}
-  Graphs: $(a^*)^* b$ and strings $\underbrace{\;a\ldots a\;}_{n}$\bigskip
-  
-\begin{tabular}[t]{@{\hspace{-8mm}}c@{\hspace{-4mm}}c@{}}
-\raisebox{6mm}{\begin{tikzpicture}
-\begin{axis}[
-    xlabel={$n$},
-    x label style={at={(1.05,0.0)}},
-    ylabel={time in secs},
-    enlargelimits=false,
-    xtick={0,5,...,30},
-    xmax=33,
-    ymax=35,
-    ytick={0,5,...,30},
-    scaled ticks=false,
-    axis lines=left,
-    width=5.5cm,
-    height=5cm, 
-    legend entries={Python,  Java 8},  
-    legend pos=north west,
-    legend cell align=left]
-\addplot[blue,mark=*, mark options={fill=white}] table {re-python2.data};  
-\addplot[cyan,mark=*, mark options={fill=white}] table {re-java.data};
-\end{axis}
-\end{tikzpicture}}
-  &
-\onslide<2>{\begin{tikzpicture}
-  \begin{axis}[
-    xlabel={$n$},
-    x label style={at={(1.05,0.0)}},
-    ylabel={time in secs},
-    enlargelimits=false,
-    ymax=35,
-    ytick={0,5,...,30},
-    axis lines=left,
-    %%scaled ticks=false,
-    width=5.5cm, 
-    height=5cm]
-%%\addplot[green,mark=square*,mark options={fill=white}] table {re2a.data};    
-\addplot[red,mark=square*,mark options={fill=white}] table {re3a.data};
-\end{axis}
-\end{tikzpicture}}
-\end{tabular}
-\end{center}
-
-\hfill\small\url{https://vimeo.com/112065252}
-\end{frame}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 
 \begin{frame}[c]
-\frametitle{Where to go on from here?}
+\frametitle{Jumping Towers}
+
+\begin{center}
+\begin{tikzpicture}[scale=1.2]
+  \draw[line width=1mm,cap=round] (0,0) -- (5,0);
+  \draw[line width=1mm,cap=round] (0,1) -- (5,1);
+
+  \draw[line width=1mm,cap=round] (0,0) -- (0,1);
+  \node at (0.5,0.5) {\textbf{\Large 3}};
+
+  \draw[line width=1mm,cap=round] (1,0) -- (1,1);
+  \node at (1.5,0.5) {\textbf{\Large 4}};
+
+  \draw[line width=1mm,cap=round] (2,0) -- (2,1);
+  \node at (2.5,0.5) {\textbf{\Large 2}};
 
-\begin{itemize}
-\item Martin Odersky (EPFL)\ldots he is currently throwing out everything
-  and starts again with the dotty compiler for Scala\medskip
+  \draw[line width=1mm,cap=round] (3,0) -- (3,1);
+  \node at (3.5,0.5) {\textbf{\Large 0}};
+  
+  \draw[line width=1mm,cap=round] (4,0) -- (4,1);
+
+  \node at (4.5,0.5) {\textbf{\Large 1}};
+  
+  \draw[line width=1mm,cap=round] (5,0) -- (5,1);
 
-\item Elm (\url{http://elm-lang.org})\ldots web applications with style\medskip   
+  \draw[->,line width=0.5mm,cap=round,out=90,in=90,relative] (0.5,1) to (1.5,1);
+  \draw[->,line width=0.5mm,cap=round,out=90,in=90,relative] (0.5,1) to (2.5,1);
+  \draw[->,line width=0.5mm,cap=round,out=90,in=90,relative] (0.5,1) to (3.5,1);
+
+  \draw[->,line width=0.5mm,cap=round,out=-90,in=-90,relative] (2.5,0) to (3.5,0);
+  \draw[->,line width=0.5mm,cap=round,out=-90,in=-90,relative] (2.5,0) to (4.5,0);
 
-\item Haskell, Ocaml, Standard ML, Scheme, \ldots 
-\end{itemize}  
+  \draw[->,line width=0.5mm,cap=round,out=90,in=90,relative] (4.5,1) to (5.7,1);
+  \node at (5.7, 0.8) {End};
+\end{tikzpicture}
+\end{center}\bigskip
+
+
+shortest: 3 $\rightarrow$ 4 $\rightarrow$ End
+
 \end{frame}
 
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\begin{frame}[c,fragile]
-\frametitle{\alert{Questions?}}
-
-{\tiny
-\begin{verbatim}
-                               *
-                              * *
-                             *   *
-                            * * * *
-                           *       *
-                          * *     * *
-                         *   *   *   *
-                        * * * * * * * *
-                       *               *
-                      * *             * *
-                     *   *           *   *
-                    * * * *         * * * *
-                   *       *       *       *
-                  * *     * *     * *     * *
-                 *   *   *   *   *   *   *   *
-                * * * * * * * * * * * * * * * *
-               *                               *
-              * *                             * *
-             *   *                           *   *
-            * * * *                         * * * *
-           *       *                       *       *
-          * *     * *                     * *     * *
-         *   *   *   *                   *   *   *   *
-        * * * * * * * *                 * * * * * * * *
-       *               *               *               *
-      * *             * *             * *             * *
-     *   *           *   *           *   *           *   *
-    * * * *         * * * *         * * * *         * * * *
-   *       *       *       *       *       *       *       *
-  * *     * *     * *     * *     * *     * *     * *     * *
- *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *
-* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-\end{verbatim}}
-
-
-\begin{textblock}{6}(8.5,3.5)
-\begin{bubble}[5cm]
-\footnotesize
-\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
-++++++++[>+>++++<<-]>++>>
-+<[-[>>+<<-]+>>]>+[-<<<[-
->[+[-]+>++>>>-<<]<[<]>>++
-++++[<<+++++>>-]+<<++.[-]
-<<]>.>+[>>]>+]
-\end{lstlisting}
-\end{bubble}
-\end{textblock}
-  
-\end{frame}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 
 \begin{frame}[c]
-\frametitle{Marks for CW6 (Part 1 + 2)}
-
-Raw marks:
+\frametitle{``Children'' / moves}
 
-\begin{itemize}
-\item 6\%: 154 students
-\item 5\%: 66
-\item 4\%: 18
-\item 3\%: 13
-\item 2\%: 2
-\item 1\%: 1
-\item 0\%: 21 
-\end{itemize}  
+\begin{center}
+  \begin{tikzpicture}
+    [grow=right,level distance=30mm,child anchor=north,line width=0.5mm]
+  \node {$[3,4,2,0,1]$}
+     child {node {$[0,1]$}}
+     child {node {$[2,0,1]$}
+        child {node {$[1]$} child [level distance=13mm] {node {End}}}
+        child {node {$[0,1]$}}
+     }
+     child {node {$[4,2,0,1]$\ldots}};
+\end{tikzpicture}
+\end{center}
+
+
+
 \end{frame}
 
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
+
+
 \end{document}