320
|
1 |
% !TEX program = xelatex
|
365
|
2 |
\documentclass[dvipsnames,14pt,t,xelatex,aspectratio=169,xcolor={table}]{beamer}
|
66
|
3 |
\usepackage{../slides}
|
|
4 |
\usepackage{../graphics}
|
|
5 |
\usepackage{../langs}
|
155
|
6 |
%%\usepackage{../data}
|
320
|
7 |
\usetikzlibrary{shapes}
|
67
|
8 |
\usepackage[export]{adjustbox}
|
66
|
9 |
|
|
10 |
\hfuzz=220pt
|
|
11 |
|
|
12 |
%\setmonofont[Scale=.88]{Consolas}
|
|
13 |
%\newfontfamily{\consolas}{Consolas}
|
|
14 |
|
|
15 |
\lstset{language=Scala,
|
|
16 |
style=mystyle,
|
|
17 |
numbersep=0pt,
|
|
18 |
numbers=none,
|
|
19 |
xleftmargin=0mm}
|
|
20 |
|
|
21 |
\newcommand{\bl}[1]{\textcolor{blue}{#1}}
|
|
22 |
|
|
23 |
% beamer stuff
|
67
|
24 |
\renewcommand{\slidecaption}{PEP (Scala) 03, King's College London}
|
66
|
25 |
|
320
|
26 |
\newcommand{\UParrow}[3]{%
|
|
27 |
\begin{textblock}{0}(#2,#3)%
|
|
28 |
\onslide<#1>{%
|
|
29 |
\begin{tikzpicture}%
|
|
30 |
\node at (0,0) [single arrow, shape border rotate=90, fill=red,text=red]{a};%
|
|
31 |
\end{tikzpicture}}%
|
|
32 |
\end{textblock}}
|
|
33 |
|
|
34 |
\newcommand{\DOWNarrow}[3]{%
|
|
35 |
\begin{textblock}{0}(#2,#3)%
|
|
36 |
\onslide<#1>{%
|
|
37 |
\begin{tikzpicture}%
|
|
38 |
\node at (0,0) [single arrow, shape border rotate=270, fill=red,text=red]{a};%
|
|
39 |
\end{tikzpicture}}%
|
|
40 |
\end{textblock}}
|
|
41 |
|
66
|
42 |
\begin{document}
|
|
43 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
44 |
\begin{frame}[t]
|
|
45 |
\frametitle{%
|
|
46 |
\begin{tabular}{@ {}c@ {}}
|
|
47 |
\\[5mm]
|
67
|
48 |
\huge PEP Scala (3)
|
66
|
49 |
\end{tabular}}
|
|
50 |
|
|
51 |
\normalsize
|
|
52 |
\begin{center}
|
|
53 |
\begin{tabular}{ll}
|
155
|
54 |
Email: & christian.urban at kcl.ac.uk\\
|
365
|
55 |
%Office: & N\liningnums{7.07} (North Wing, Bush House)\bigskip\\
|
320
|
56 |
Slides \& Code: & KEATS\bigskip\\
|
365
|
57 |
%Office Hours: & Thursdays 12:00 -- 14:00\\
|
|
58 |
%Additionally: & (for Scala) Tuesdays 10:45 -- 11:45\\
|
66
|
59 |
\end{tabular}
|
|
60 |
\end{center}
|
|
61 |
|
|
62 |
\end{frame}
|
|
63 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
64 |
|
217
|
65 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
365
|
66 |
% \begin{frame}[c]
|
|
67 |
% \frametitle{Preliminary 6}
|
217
|
68 |
|
365
|
69 |
% Raw marks (261 submissions):\bigskip
|
217
|
70 |
|
365
|
71 |
% \begin{itemize}
|
|
72 |
% \item 3\%: \hspace{4mm}219
|
|
73 |
% \item 2\%: \hspace{4mm}19
|
|
74 |
% \item 1\%: \hspace{4mm}0
|
|
75 |
% \item 0\%: \hspace{4mm}23 \;(4 no submission)
|
|
76 |
% \end{itemize}
|
|
77 |
% \end{frame}
|
217
|
78 |
|
|
79 |
|
|
80 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
81 |
|
66
|
82 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
67
|
83 |
\begin{frame}[c,fragile]
|
|
84 |
|
155
|
85 |
\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
|
217
|
86 |
def collatz(n: Long) : Long =
|
|
87 |
{
|
|
88 |
val toReturn = collatzHelper(n, 0)
|
|
89 |
toReturn
|
|
90 |
}
|
|
91 |
\end{lstlisting}
|
|
92 |
|
|
93 |
\pause
|
|
94 |
\bigskip
|
|
95 |
\rule{11cm}{0.3mm}
|
|
96 |
\bigskip
|
67
|
97 |
|
217
|
98 |
\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
|
|
99 |
def collatz(n: Long) : Long =
|
|
100 |
collatzHelper(n, 0)
|
320
|
101 |
\end{lstlisting}
|
67
|
102 |
|
|
103 |
\end{frame}
|
|
104 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
105 |
|
|
106 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
155
|
107 |
\begin{frame}[c,fragile]
|
320
|
108 |
\frametitle{Default Arguments}
|
67
|
109 |
|
217
|
110 |
\small
|
320
|
111 |
\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-3mm]
|
|
112 |
def collatzHelper(n: Int, a: Int = 0) : Int = ...
|
217
|
113 |
|
67
|
114 |
|
320
|
115 |
collatzHelper(n, 3)
|
|
116 |
collatzHelper(n, 0)
|
|
117 |
|
|
118 |
collatzHelper(n) // a = 0
|
155
|
119 |
\end{lstlisting}
|
217
|
120 |
|
320
|
121 |
\DOWNarrow{1}{10.7}{3.4}
|
67
|
122 |
|
|
123 |
\end{frame}
|
|
124 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
125 |
|
|
126 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
320
|
127 |
\begin{frame}[c,fragile]
|
|
128 |
\frametitle{Last Week: Options \& HO Funs.}
|
67
|
129 |
|
320
|
130 |
\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
|
|
131 |
List(7,2,3,4,5,6).find(_ < 4)
|
|
132 |
res: Option[Int] = Some(2)
|
|
133 |
|
|
134 |
|
|
135 |
List(5,6,7,8,9).find(_ < 4)
|
|
136 |
res: Option[Int] = None
|
|
137 |
|
|
138 |
|
|
139 |
List(1,2,3,4,5).map(x => x * x)
|
|
140 |
res: List[Int] = List(1, 4, 9, 16, 25)
|
|
141 |
\end{lstlisting}
|
|
142 |
|
|
143 |
\end{frame}
|
|
144 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
145 |
|
|
146 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
147 |
\begin{frame}[c,fragile]
|
|
148 |
\frametitle{Web-Crawler (1)}
|
|
149 |
|
|
150 |
\small
|
|
151 |
\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-7mm]
|
|
152 |
def get_page(url: String) : String = {
|
|
153 |
Try(fromURL(url)("ISO-8859-1").take(10000).mkString)
|
|
154 |
.getOrElse { println(s" Problem with: $url"); ""}
|
|
155 |
}
|
|
156 |
\end{lstlisting}
|
|
157 |
\end{frame}
|
|
158 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
159 |
|
|
160 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
161 |
\begin{frame}[c,fragile]
|
|
162 |
\frametitle{Web-Crawler (2)}
|
|
163 |
|
|
164 |
\small
|
|
165 |
\begin{lstlisting}[language=Scala, numbers=none,
|
|
166 |
xleftmargin=-7mm, escapeinside={(*@}{@*)}]
|
|
167 |
val http_pattern = """(*@\textcolor{codegreen}{"}@*)https?://[\^(*@\textcolor{codegreen}{"}@*)]*(*@\textcolor{codegreen}{"}@*)""".r
|
|
168 |
val email_pattern =
|
|
169 |
"""([a-z\d\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})""".r
|
|
170 |
|
|
171 |
|
|
172 |
def unquote(s: String) = s.drop(1).dropRight(1)
|
|
173 |
|
|
174 |
|
|
175 |
def get_all_URLs(page: String): Set[String] =
|
|
176 |
http_pattern.findAllIn(page).map(unquote).toSet
|
|
177 |
|
|
178 |
// returns all URLs in a page
|
|
179 |
\end{lstlisting}
|
|
180 |
|
|
181 |
\end{frame}
|
|
182 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
183 |
|
|
184 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
185 |
\begin{frame}[c,fragile]
|
|
186 |
\frametitle{Web-Crawler (3)}
|
|
187 |
|
|
188 |
\small
|
|
189 |
\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
|
|
190 |
def crawl(url: String, n: Int) : Unit = {
|
|
191 |
if (n == 0) ()
|
|
192 |
else {
|
|
193 |
println(s" Visiting: $n $url")
|
|
194 |
val page = get_page(url)
|
|
195 |
for (u <- get_all_URLs(page))
|
|
196 |
crawl(u, n - 1)
|
|
197 |
}
|
|
198 |
}
|
|
199 |
\end{lstlisting}
|
|
200 |
\end{frame}
|
|
201 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
202 |
|
|
203 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
204 |
\begin{frame}[c,fragile]
|
|
205 |
\frametitle{Email Harvester}
|
|
206 |
|
|
207 |
\small
|
|
208 |
\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-3mm]
|
|
209 |
def emails(url: String, n: Int) : Set[String] = {
|
|
210 |
if (n == 0) Set()
|
|
211 |
else {
|
|
212 |
println(s" Visiting: $n $url")
|
|
213 |
val page = get_page(url)
|
|
214 |
val new_emails =
|
|
215 |
email_pattern.findAllIn(page).toSet
|
|
216 |
new_emails ++
|
|
217 |
(for (u <- get_all_URLs(page))
|
|
218 |
yield emails(u, n - 1)).flatten
|
|
219 |
}
|
|
220 |
}
|
|
221 |
|
|
222 |
\end{lstlisting}
|
|
223 |
\end{frame}
|
|
224 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
225 |
|
|
226 |
|
|
227 |
|
|
228 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
68
|
229 |
\begin{frame}[c]
|
217
|
230 |
\frametitle{Jumping Towers}
|
|
231 |
|
|
232 |
\begin{center}
|
320
|
233 |
\begin{tikzpicture}[scale=1.3]
|
217
|
234 |
\draw[line width=1mm,cap=round] (0,0) -- (5,0);
|
|
235 |
\draw[line width=1mm,cap=round] (0,1) -- (5,1);
|
|
236 |
|
|
237 |
\draw[line width=1mm,cap=round] (0,0) -- (0,1);
|
|
238 |
\node at (0.5,0.5) {\textbf{\Large 3}};
|
|
239 |
|
|
240 |
\draw[line width=1mm,cap=round] (1,0) -- (1,1);
|
|
241 |
\node at (1.5,0.5) {\textbf{\Large 4}};
|
|
242 |
|
|
243 |
\draw[line width=1mm,cap=round] (2,0) -- (2,1);
|
|
244 |
\node at (2.5,0.5) {\textbf{\Large 2}};
|
67
|
245 |
|
217
|
246 |
\draw[line width=1mm,cap=round] (3,0) -- (3,1);
|
|
247 |
\node at (3.5,0.5) {\textbf{\Large 0}};
|
|
248 |
|
|
249 |
\draw[line width=1mm,cap=round] (4,0) -- (4,1);
|
|
250 |
|
|
251 |
\node at (4.5,0.5) {\textbf{\Large 1}};
|
|
252 |
|
|
253 |
\draw[line width=1mm,cap=round] (5,0) -- (5,1);
|
67
|
254 |
|
217
|
255 |
\draw[->,line width=0.5mm,cap=round,out=90,in=90,relative] (0.5,1) to (1.5,1);
|
|
256 |
\draw[->,line width=0.5mm,cap=round,out=90,in=90,relative] (0.5,1) to (2.5,1);
|
|
257 |
\draw[->,line width=0.5mm,cap=round,out=90,in=90,relative] (0.5,1) to (3.5,1);
|
|
258 |
|
|
259 |
\draw[->,line width=0.5mm,cap=round,out=-90,in=-90,relative] (2.5,0) to (3.5,0);
|
|
260 |
\draw[->,line width=0.5mm,cap=round,out=-90,in=-90,relative] (2.5,0) to (4.5,0);
|
67
|
261 |
|
217
|
262 |
\draw[->,line width=0.5mm,cap=round,out=90,in=90,relative] (4.5,1) to (5.7,1);
|
|
263 |
\node at (5.7, 0.8) {End};
|
|
264 |
\end{tikzpicture}
|
|
265 |
\end{center}\bigskip
|
|
266 |
|
|
267 |
|
|
268 |
shortest: 3 $\rightarrow$ 4 $\rightarrow$ End
|
|
269 |
|
67
|
270 |
\end{frame}
|
|
271 |
|
|
272 |
|
|
273 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
274 |
|
70
|
275 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
276 |
\begin{frame}[c]
|
366
|
277 |
\frametitle{next moves}
|
70
|
278 |
|
217
|
279 |
\begin{center}
|
|
280 |
\begin{tikzpicture}
|
|
281 |
[grow=right,level distance=30mm,child anchor=north,line width=0.5mm]
|
|
282 |
\node {$[3,4,2,0,1]$}
|
|
283 |
child {node {$[0,1]$}}
|
|
284 |
child {node {$[2,0,1]$}
|
|
285 |
child {node {$[1]$} child [level distance=13mm] {node {End}}}
|
|
286 |
child {node {$[0,1]$}}
|
|
287 |
}
|
|
288 |
child {node {$[4,2,0,1]$\ldots}};
|
|
289 |
\end{tikzpicture}
|
|
290 |
\end{center}
|
|
291 |
|
366
|
292 |
\begin{textblock}{4}(13,12)
|
|
293 |
\includegraphics[scale=0.06]{../pics/chess.jpg}
|
|
294 |
\end{textblock}
|
|
295 |
|
320
|
296 |
\end{frame}
|
|
297 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
217
|
298 |
|
320
|
299 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
300 |
\begin{frame}[c,fragile]
|
|
301 |
\frametitle{Reverse Polish Notation}
|
|
302 |
|
|
303 |
{\Large\bl{$(3 + 1) * (2 + 9)$}}\bigskip
|
|
304 |
|
|
305 |
{\Large$\Rightarrow$}\bigskip
|
|
306 |
|
|
307 |
{\;\;\Large\bl{$3\;\;1\;+\;2\;\;9\;+\;*$}}
|
323
|
308 |
|
|
309 |
\begin{textblock}{3}(11,4)
|
|
310 |
\begin{onlyenv}<2>
|
|
311 |
\begin{lstlisting}[language=JVMIS]
|
|
312 |
ldc 3
|
|
313 |
ldc 1
|
|
314 |
iadd
|
|
315 |
ldc 2
|
|
316 |
ldc 9
|
|
317 |
iadd
|
|
318 |
imul
|
|
319 |
\end{lstlisting}
|
|
320 |
\end{onlyenv}
|
|
321 |
\end{textblock}
|
|
322 |
|
320
|
323 |
\end{frame}
|
|
324 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
325 |
|
|
326 |
|
365
|
327 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
328 |
% \begin{frame}[c,fragile]
|
|
329 |
% \frametitle{Sudoku}
|
320
|
330 |
|
365
|
331 |
% A very simple-minded version on 110 problems:\bigskip
|
320
|
332 |
|
365
|
333 |
% \begin{itemize}
|
|
334 |
% \item 1 core: 800 secs
|
|
335 |
% \item 2 cores: 400 secs
|
|
336 |
% \item 8 cores: 290 secs
|
|
337 |
% \item 18 cores: 142 secs
|
|
338 |
% \end{itemize}
|
217
|
339 |
|
365
|
340 |
% \end{frame}
|
|
341 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
320
|
342 |
|
365
|
343 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
344 |
% \begin{frame}[t]
|
323
|
345 |
|
365
|
346 |
% \begin{center}
|
|
347 |
% \includegraphics[scale=0.3]{../pics/blow.png}
|
|
348 |
% \end{center}
|
323
|
349 |
|
365
|
350 |
% \begin{textblock}{14}(2,11.4)
|
|
351 |
% \large\bf{}Mind-Blowing Programming Languages:\\
|
|
352 |
% \centering JavaScript
|
|
353 |
% \end{textblock}
|
|
354 |
% \end{frame}
|
|
355 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
217
|
356 |
|
367
|
357 |
\begin{frame}<1-10>
|
|
358 |
\end{frame}
|
|
359 |
|
66
|
360 |
\end{document}
|
|
361 |
|
|
362 |
|
|
363 |
\end{document}
|
|
364 |
|
|
365 |
%%% Local Variables:
|
|
366 |
%%% mode: latex
|
|
367 |
%%% TeX-master: t
|
|
368 |
%%% End:
|
|
369 |
|