slides/slides03.tex
changeset 217 e689375abcc1
parent 158 94b11ac19b41
child 218 22705d22c105
equal deleted inserted replaced
216:8c868feb917b 217:e689375abcc1
    18 
    18 
    19 \newcommand{\bl}[1]{\textcolor{blue}{#1}}     
    19 \newcommand{\bl}[1]{\textcolor{blue}{#1}}     
    20 
    20 
    21 % beamer stuff 
    21 % beamer stuff 
    22 \renewcommand{\slidecaption}{PEP (Scala) 03, King's College London}
    22 \renewcommand{\slidecaption}{PEP (Scala) 03, King's College London}
    23 
       
    24 \begin{filecontents}{re3a.data}
       
    25 1 0.00003
       
    26 500001 0.22527
       
    27 1000001 0.62752
       
    28 1500001 0.88485
       
    29 2000001 1.39815
       
    30 2500001 1.68619
       
    31 3000001 1.94957
       
    32 3500001 2.15878
       
    33 4000001 2.59918
       
    34 4500001 5.90679
       
    35 5000001 13.11295
       
    36 5500001 19.15376
       
    37 6000001 40.16373
       
    38 \end{filecontents}
       
    39 \begin{filecontents}{re-python2.data}
       
    40 1 0.033
       
    41 5 0.036
       
    42 10 0.034
       
    43 15 0.036
       
    44 18 0.059
       
    45 19 0.084
       
    46 20 0.141
       
    47 21 0.248
       
    48 22 0.485
       
    49 23 0.878
       
    50 24 1.71
       
    51 25 3.40
       
    52 26 7.08
       
    53 27 14.12
       
    54 28 26.69
       
    55 \end{filecontents}
       
    56 
       
    57 \begin{filecontents}{re-java.data}
       
    58 5  0.00298
       
    59 10  0.00418
       
    60 15  0.00996
       
    61 16  0.01710
       
    62 17  0.03492
       
    63 18  0.03303
       
    64 19  0.05084
       
    65 20  0.10177
       
    66 21  0.19960
       
    67 22  0.41159
       
    68 23  0.82234
       
    69 24  1.70251
       
    70 25  3.36112
       
    71 26  6.63998
       
    72 27  13.35120
       
    73 28  29.81185
       
    74 \end{filecontents}
       
    75 
    23 
    76 \begin{document}
    24 \begin{document}
    77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    25 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    78 \begin{frame}[t]
    26 \begin{frame}[t]
    79 \frametitle{%
    27 \frametitle{%
    86   \begin{center}
    34   \begin{center}
    87   \begin{tabular}{ll}
    35   \begin{tabular}{ll}
    88     Email:  & christian.urban at kcl.ac.uk\\
    36     Email:  & christian.urban at kcl.ac.uk\\
    89     Office: & N7.07 (North Wing, Bush House)\\
    37     Office: & N7.07 (North Wing, Bush House)\\
    90     Slides \& Code: & KEATS\medskip\\
    38     Slides \& Code: & KEATS\medskip\\
    91     Scala Office & \\
    39     Office Hours: &  \alert{next Monday} 11 -- 12 \& 13 -- 14\\
    92     Hours: &  Thursdays 11 -- 13\\
       
    93   \end{tabular}
    40   \end{tabular}
    94   \end{center}
    41   \end{center}
    95 
    42 
    96 
    43 
    97 \end{frame}
    44 \end{frame}
    98 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
    45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
    99 
    46 
       
    47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
       
    48 
       
    49 \begin{frame}[c]
       
    50 \frametitle{Marks for CW6 (Part 1 + 2)}
       
    51 
       
    52 Raw marks (234 submissions):
       
    53 
       
    54 \begin{itemize}
       
    55 \item 6\%: \hspace{4mm}163 students
       
    56 \item 5\%: \hspace{4mm}29
       
    57 \item 4\%: \hspace{4mm}3
       
    58 \item 3\%: \hspace{4mm}13
       
    59 \item 2\%: \hspace{4mm}3
       
    60 \item 1\%: \hspace{4mm}0
       
    61 \item 0\%: \hspace{4mm}23 
       
    62 \end{itemize}  
       
    63 \end{frame}
       
    64 
       
    65 
       
    66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
    67 
       
    68 
   100 
    69 
   101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   102 \begin{frame}[c,fragile]
    71 \begin{frame}[c,fragile]
   103 
    72 
   104 \begin{textblock}{6}(0.5,0.5)
    73 \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
   105 \begin{bubble}[11.5cm]
    74 def collatz(n: Long) : Long =
   106 \footnotesize
    75   {
   107 \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
    76     val toReturn = collatzHelper(n, 0)
   108 import java.util.concurrent._
    77     toReturn
   109 import java.util.concurrent.atomic._
    78   } 
   110 
       
   111   def collatz(input:Int){
       
   112           CollatzConjecture(input);
       
   113           println(count.get());
       
   114       }
       
   115       def collatz_max(input:Int){
       
   116           val List = new Array[Int](input)
       
   117             for (i <- 0 to input-1){
       
   118                 CollaĵConjecture(i);
       
   119                 List(i)=count.get();
       
   120                 count.set(0);
       
   121             }
       
   122             val max = new AtomicInteger();
       
   123             max.set(List(0));
       
   124             val index = new AtomicInteger();
       
   125             index.set(1);
       
   126  
       
   127 \end{lstlisting}
    79 \end{lstlisting}
   128 \end{bubble}
    80 
   129 \end{textblock}
    81 \pause
       
    82 \bigskip
       
    83 \rule{11cm}{0.3mm}
       
    84 \bigskip
       
    85 
       
    86 \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
       
    87 def collatz(n: Long) : Long =
       
    88   collatzHelper(n, 0)
       
    89 \end{lstlisting}\pause
       
    90 
   130 
    91 
   131 \end{frame}
    92 \end{frame}
   132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
    93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
   133 
    94 
   134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   135 \begin{frame}[c,fragile]
    96 \begin{frame}[c,fragile]
   136 
    97 
   137 \begin{textblock}{6}(0.5,0.5)
    98 \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
   138 \begin{bubble}[11.5cm]
    99 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)}
   139 \footnotesize
   100 \end{lstlisting}\bigskip
   140 \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
   101 
   141              for(i<-0 to input-1){
   102 \tiny
   142                 val temp :Int=max.get();
   103 \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
   143                 if (temp < List(i)){
   104 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)}
   144                     max.set(List(i));
   105 \end{lstlisting}\pause
   145                     index.set(i);
   106 
   146                 }
   107 
   147             }
   108 \end{frame}
   148             println("("+max.get() +","+ index.get()+ ")");
   109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
   149       }
   110 
   150 
   111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   151       def CollatzConjecture(n: Long): Long = {
   112 \begin{frame}[c,fragile]
   152         count.incrementAndGet();
   113 
   153         if (n <= 1)
   114 \small
   154             1
   115 \begin{lstlisting}[language=Scala, xleftmargin=-4mm,numbers=left]
   155         else if (n\%2 ==0)
   116  def process_ratings(lines: List[String]) = {
   156             CollatzConjecture(n/2);
   117     val values = List[(String,String)]()
   157             else
   118 
   158                CollatzConjecture((3*n)+1);
   119     for(line <- lines){
   159    }
   120         val splitList = line.split(",").toList
       
   121 
       
   122         if(splitList(2).toInt >= 4){
       
   123             val userID = splitList(0)
       
   124             val movieID = splitList(1)
       
   125             val tuple = (userID, movieID)
       
   126             tuple :: values
       
   127         }
       
   128     }
       
   129     
       
   130     values
   160  }
   131  }
   161 \end{lstlisting}
   132 \end{lstlisting}
   162 \end{bubble}
   133 
   163 \end{textblock}
   134 \normalsize
       
   135 What does this function always return?
       
   136 
   164 
   137 
   165 \end{frame}
   138 \end{frame}
   166 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
   139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
   167 
   140 
   168 
   141 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
   169 
   142 
   170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   171 \begin{frame}[c]
   143 \begin{frame}[c]
   172   \frametitle{CW3 (1 Part): Regexes}
   144 \frametitle{Jumping Towers}
       
   145 
       
   146 \begin{center}
       
   147 \begin{tikzpicture}[scale=1.2]
       
   148   \draw[line width=1mm,cap=round] (0,0) -- (5,0);
       
   149   \draw[line width=1mm,cap=round] (0,1) -- (5,1);
       
   150 
       
   151   \draw[line width=1mm,cap=round] (0,0) -- (0,1);
       
   152   \node at (0.5,0.5) {\textbf{\Large 3}};
       
   153 
       
   154   \draw[line width=1mm,cap=round] (1,0) -- (1,1);
       
   155   \node at (1.5,0.5) {\textbf{\Large 4}};
       
   156 
       
   157   \draw[line width=1mm,cap=round] (2,0) -- (2,1);
       
   158   \node at (2.5,0.5) {\textbf{\Large 2}};
       
   159 
       
   160   \draw[line width=1mm,cap=round] (3,0) -- (3,1);
       
   161   \node at (3.5,0.5) {\textbf{\Large 0}};
   173   
   162   
       
   163   \draw[line width=1mm,cap=round] (4,0) -- (4,1);
       
   164 
       
   165   \node at (4.5,0.5) {\textbf{\Large 1}};
       
   166   
       
   167   \draw[line width=1mm,cap=round] (5,0) -- (5,1);
       
   168 
       
   169   \draw[->,line width=0.5mm,cap=round,out=90,in=90,relative] (0.5,1) to (1.5,1);
       
   170   \draw[->,line width=0.5mm,cap=round,out=90,in=90,relative] (0.5,1) to (2.5,1);
       
   171   \draw[->,line width=0.5mm,cap=round,out=90,in=90,relative] (0.5,1) to (3.5,1);
       
   172 
       
   173   \draw[->,line width=0.5mm,cap=round,out=-90,in=-90,relative] (2.5,0) to (3.5,0);
       
   174   \draw[->,line width=0.5mm,cap=round,out=-90,in=-90,relative] (2.5,0) to (4.5,0);
       
   175 
       
   176   \draw[->,line width=0.5mm,cap=round,out=90,in=90,relative] (4.5,1) to (5.7,1);
       
   177   \node at (5.7, 0.8) {End};
       
   178 \end{tikzpicture}
       
   179 \end{center}\bigskip
       
   180 
       
   181 
       
   182 shortest: 3 $\rightarrow$ 4 $\rightarrow$ End
       
   183 
       
   184 \end{frame}
       
   185 
       
   186 
       
   187 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   188 
       
   189 
       
   190 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
       
   191 
       
   192 \begin{frame}[c]
       
   193 \frametitle{``Children'' / moves}
       
   194 
   174 \begin{center}
   195 \begin{center}
   175   Graphs: $(a^*)^* b$ and strings $\underbrace{\;a\ldots a\;}_{n}$\bigskip
   196   \begin{tikzpicture}
   176   
   197     [grow=right,level distance=30mm,child anchor=north,line width=0.5mm]
   177 \begin{tabular}[t]{@{\hspace{-8mm}}c@{\hspace{-4mm}}c@{}}
   198   \node {$[3,4,2,0,1]$}
   178 \raisebox{6mm}{\begin{tikzpicture}
   199      child {node {$[0,1]$}}
   179 \begin{axis}[
   200      child {node {$[2,0,1]$}
   180     xlabel={$n$},
   201         child {node {$[1]$} child [level distance=13mm] {node {End}}}
   181     x label style={at={(1.05,0.0)}},
   202         child {node {$[0,1]$}}
   182     ylabel={time in secs},
   203      }
   183     enlargelimits=false,
   204      child {node {$[4,2,0,1]$\ldots}};
   184     xtick={0,5,...,30},
   205 \end{tikzpicture}
   185     xmax=33,
       
   186     ymax=35,
       
   187     ytick={0,5,...,30},
       
   188     scaled ticks=false,
       
   189     axis lines=left,
       
   190     width=5.5cm,
       
   191     height=5cm, 
       
   192     legend entries={Python,  Java 8},  
       
   193     legend pos=north west,
       
   194     legend cell align=left]
       
   195 \addplot[blue,mark=*, mark options={fill=white}] table {re-python2.data};  
       
   196 \addplot[cyan,mark=*, mark options={fill=white}] table {re-java.data};
       
   197 \end{axis}
       
   198 \end{tikzpicture}}
       
   199   &
       
   200 \onslide<2>{\begin{tikzpicture}
       
   201   \begin{axis}[
       
   202     xlabel={$n$},
       
   203     x label style={at={(1.05,0.0)}},
       
   204     ylabel={time in secs},
       
   205     enlargelimits=false,
       
   206     ymax=35,
       
   207     ytick={0,5,...,30},
       
   208     axis lines=left,
       
   209     %%scaled ticks=false,
       
   210     width=5.5cm, 
       
   211     height=5cm]
       
   212 %%\addplot[green,mark=square*,mark options={fill=white}] table {re2a.data};    
       
   213 \addplot[red,mark=square*,mark options={fill=white}] table {re3a.data};
       
   214 \end{axis}
       
   215 \end{tikzpicture}}
       
   216 \end{tabular}
       
   217 \end{center}
   206 \end{center}
   218 
   207 
   219 \hfill\small\url{https://vimeo.com/112065252}
   208 
   220 \end{frame}
   209 
   221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
   210 \end{frame}
   222 
   211 
   223 \begin{frame}[c]
   212 
   224 \frametitle{Where to go on from here?}
   213 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   225 
   214 
   226 \begin{itemize}
   215 
   227 \item Martin Odersky (EPFL)\ldots he is currently throwing out everything
       
   228   and starts again with the dotty compiler for Scala\medskip
       
   229 
       
   230 \item Elm (\url{http://elm-lang.org})\ldots web applications with style\medskip   
       
   231 
       
   232 \item Haskell, Ocaml, Standard ML, Scheme, \ldots 
       
   233 \end{itemize}  
       
   234 \end{frame}
       
   235 
       
   236 
       
   237 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   238 
       
   239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   240 \begin{frame}[c,fragile]
       
   241 \frametitle{\alert{Questions?}}
       
   242 
       
   243 {\tiny
       
   244 \begin{verbatim}
       
   245                                *
       
   246                               * *
       
   247                              *   *
       
   248                             * * * *
       
   249                            *       *
       
   250                           * *     * *
       
   251                          *   *   *   *
       
   252                         * * * * * * * *
       
   253                        *               *
       
   254                       * *             * *
       
   255                      *   *           *   *
       
   256                     * * * *         * * * *
       
   257                    *       *       *       *
       
   258                   * *     * *     * *     * *
       
   259                  *   *   *   *   *   *   *   *
       
   260                 * * * * * * * * * * * * * * * *
       
   261                *                               *
       
   262               * *                             * *
       
   263              *   *                           *   *
       
   264             * * * *                         * * * *
       
   265            *       *                       *       *
       
   266           * *     * *                     * *     * *
       
   267          *   *   *   *                   *   *   *   *
       
   268         * * * * * * * *                 * * * * * * * *
       
   269        *               *               *               *
       
   270       * *             * *             * *             * *
       
   271      *   *           *   *           *   *           *   *
       
   272     * * * *         * * * *         * * * *         * * * *
       
   273    *       *       *       *       *       *       *       *
       
   274   * *     * *     * *     * *     * *     * *     * *     * *
       
   275  *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *
       
   276 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
       
   277 \end{verbatim}}
       
   278 
       
   279 
       
   280 \begin{textblock}{6}(8.5,3.5)
       
   281 \begin{bubble}[5cm]
       
   282 \footnotesize
       
   283 \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
       
   284 ++++++++[>+>++++<<-]>++>>
       
   285 +<[-[>>+<<-]+>>]>+[-<<<[-
       
   286 >[+[-]+>++>>>-<<]<[<]>>++
       
   287 ++++[<<+++++>>-]+<<++.[-]
       
   288 <<]>.>+[>>]>+]
       
   289 \end{lstlisting}
       
   290 \end{bubble}
       
   291 \end{textblock}
       
   292   
       
   293 \end{frame}
       
   294 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   295 
       
   296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
       
   297 
       
   298 \begin{frame}[c]
       
   299 \frametitle{Marks for CW6 (Part 1 + 2)}
       
   300 
       
   301 Raw marks:
       
   302 
       
   303 \begin{itemize}
       
   304 \item 6\%: 154 students
       
   305 \item 5\%: 66
       
   306 \item 4\%: 18
       
   307 \item 3\%: 13
       
   308 \item 2\%: 2
       
   309 \item 1\%: 1
       
   310 \item 0\%: 21 
       
   311 \end{itemize}  
       
   312 \end{frame}
       
   313 
       
   314 
       
   315 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   316 
   216 
   317 \end{document}
   217 \end{document}
   318 
   218 
   319 
   219 
   320 \end{document}
   220 \end{document}