--- a/slides/slides03.tex Fri Nov 24 01:26:01 2017 +0000
+++ b/slides/slides03.tex Fri Nov 24 03:10:23 2017 +0000
@@ -2,7 +2,7 @@
\usepackage{../slides}
\usepackage{../graphics}
\usepackage{../langs}
-%\usepackage{../data}
+%%\usepackage{../data}
\usepackage[export]{adjustbox}
\hfuzz=220pt
@@ -21,9 +21,59 @@
% 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]
\frametitle{%
@@ -35,9 +85,11 @@
\normalsize
\begin{center}
\begin{tabular}{ll}
- Email: & christian.urban at kcl.ac.uk\\
- Office: & S1.27 (1st floor Strand Building)\\
- Slides \& Code: & KEATS
+ Email: & christian.urban at kcl.ac.uk\\
+ Office: & N7.07 (North Wing, Bush House)\\
+ Slides \& Code: & KEATS\medskip\\
+ Scala Office & \\
+ Hours: & Thursdays 11 -- 13\\
\end{tabular}
\end{center}
@@ -45,181 +97,79 @@
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\begin{frame}[c, fragile]
-\frametitle{The Joy of Immutability}
-
-\begin{itemize}
-\item If you need to manipulate some data in a list say, then you make
- a new list with the updated values, rather than revise the original
- list. Easy!\medskip
-
- {\small
- \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
- val old_list = List(1, 2, 3, 5)
- val new_list = 0 :: old_list
- \end{lstlisting}}
-
-\item You do not have to be defensive about who can access the data
- (concurrency, lazyness).
-\end{itemize}
-\end{frame}
-
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\begin{frame}[t]
-\frametitle{Email: Hate 'val'}
-
-\mbox{}\\[-25mm]\mbox{}
-
-\begin{center}
- \begin{bubble}[10.5cm]
- Subject: \textbf{Hate '\textbf{\texttt{val}}'}\hfill 01:00 AM\medskip\\
-
- Hello Mr Urban,\medskip\\
-
- I just wanted to ask, how are we suppose to work
- with the completely useless \textbf{\texttt{val}}, that can’t be changed ever? Why is
- this rule active at all? I’ve spent 4 hours not thinking on the
- coursework, but how to bypass this annoying rule. What’s the whole
- point of all these coursework, when we can’t use everything Scala
- gives us?!?\medskip\\
-
- Regards.\\
- \mbox{}\hspace{5mm}\textcolor{black!50}{<<deleted>>}\\
- \end{bubble}
-\end{center}
-
-\end{frame}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\begin{frame}[c]
-
-\mbox{}\\[-25mm]\mbox{}
-
-\begin{center}
- \begin{bubble}[10.5cm]
- Subject: \textbf{Re: Hate '\textbf{\texttt{val}}'}\hfill 01:02 AM\bigskip\bigskip\\
-
- \textcolor{black!70}{
- \textit{\large<<my usual rant about fp\ldots\\ concurrency bla bla\ldots{} better programs
- yada>>}}\bigskip\bigskip\bigskip
-
- PS: What are you trying to do where you desperately want to use \texttt{var}?
- \end{bubble}
-\end{center}
-
-\end{frame}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[c,fragile]
\begin{textblock}{6}(0.5,0.5)
\begin{bubble}[11.5cm]
- \small
- Subject: \textbf{Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 01:04 AM\medskip\\
+\footnotesize
+\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
+import java.util.concurrent._
+import java.util.concurrent.atomic._
- \textbf{Right now my is\_legal function works fine:}
-
-\footnotesize\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
- def is_legal(dim: Int, path: Path)(x: Pos): Boolean = {
- var boolReturn = false
- if(x._1 > dim || x._2 > dim || x._1 < 0 || x._2 < 0) {
- else { var breakLoop = false
- if(path == Nil) { boolReturn = true }
- else { for(i <- 0 until path.length) {
- if(breakLoop == false) {
- if(path(i) == x) {
- boolReturn = true
- breakLoop = true
- }
- else { boolReturn = false }
- } else breakLoop
+ 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);
}
- }
- boolReturn
- }
+ val max = new AtomicInteger();
+ max.set(List(0));
+ val index = new AtomicInteger();
+ index.set(1);
+
\end{lstlisting}
\end{bubble}
\end{textblock}
-\begin{textblock}{6}(8.2,11.8)
-\begin{bubble}[5.5cm]\footnotesize\bf
-\ldots{}but I can’t make it work with boolReturn being val. What approach would
-you recommend in this case, and is using var in this case justified?
-\end{bubble}
-\end{textblock}
-
-\only<2>{
-\begin{textblock}{6}(0.3,11.8)
- \begin{bubble}[3.1cm]
- \textbf{Me:} \includegraphics[scale=0.08, valign=t]{../pics/throwup.jpg}
- \end{bubble}
-\end{textblock}}
-
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\begin{frame}[t,fragile]
-
-\mbox{}\\[-25mm]\mbox{}
+\begin{frame}[c,fragile]
-\begin{textblock}{6}(0.5,2)
- \begin{bubble}[11.5cm]
- Subject: \textbf{Re: Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 01:06 AM\bigskip\\
- \small
-
- OK. So you want to make sure that the \texttt{x}-position is not outside the
- board....and furthermore you want to make sure that the \texttt{x}-position
- is not yet in the path list. How about something like\bigskip
+\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()+ ")");
+ }
-\footnotesize\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
- def is_legal(dim: Int, path: Path)(x: Pos): Boolean =
- ...<<some board conditions>>... && !path.contains(x)
-\end{lstlisting}\bigskip
-
- \small Does not even contain a \texttt{val}.
- \end{bubble}
-\end{textblock}
-
-\begin{textblock}{6}(7,12)
-\footnotesize\textcolor{black!50}{(This is all on one line)}
+ def CollatzConjecture(n: Long): Long = {
+ count.incrementAndGet();
+ if (n <= 1)
+ 1
+ else if (n\%2 ==0)
+ CollatzConjecture(n/2);
+ else
+ CollatzConjecture((3*n)+1);
+ }
+ }
+\end{lstlisting}
+\end{bubble}
\end{textblock}
\end{frame}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\begin{frame}[t,fragile]
-
-\mbox{}\\[-15mm]\mbox{}
-
-\begin{textblock}{6}(1,3)
- \begin{bubble}[10.5cm]
- Subject: \textbf{Re: Re: Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 11:02 AM\bigskip\bigskip\\
-
- THANK YOU! You made me change my coding perspective. Because of you,
- I figured out the next one\ldots
- \end{bubble}
-\end{textblock}
-
-\only<2>{
-\begin{textblock}{6}(0.3,11.8)
- \begin{bubble}[3.1cm]
- \textbf{Me:} \includegraphics[scale=0.08]{../pics/happy.jpg}
- \end{bubble}
-\end{textblock}}
-
-\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[c]
- \frametitle{CW3: Regexes (1 Part)}
+ \frametitle{CW3 (1 Part): Regexes}
\begin{center}
Graphs: $(a^*)^* b$ and strings $\underbrace{\;a\ldots a\;}_{n}$\bigskip
@@ -287,32 +237,77 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\begin{frame}[c]
-\frametitle{\begin{tabular}{c}\\[3cm]\alert{Questions?}\end{tabular}}
+\begin{frame}[c,fragile]
+\frametitle{\alert{Questions?}}
-\mbox{}\footnotesize
-Thanks: ``\it{}By the way - Scala is really getting quite fun
-when you start to get the hang of it\ldots''
+{\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)}
+\frametitle{Marks for CW6 (Part 1 + 2)}
-Absolute raw marks, alleged collusions still included:
+Raw marks:
\begin{itemize}
-\item 0\%: 18 students
-\item 1\%: 2
-\item 2\%: 11
-\item 3\%: 29
+\item 0\%: 21 students
+\item 1\%: 1
+\item 2\%: 2
+\item 3\%: 13
\item 4\%: 18
-\item 5\%: 33
-\item 6\%: 55
-\item 7\%: 62
+\item 5\%: 66
+\item 6\%: 154
\end{itemize}
\end{frame}