--- a/cws/cw01.tex Sat Jun 22 08:39:52 2019 +0100
+++ b/cws/cw01.tex Wed Jul 24 14:22:06 2019 +0100
@@ -13,10 +13,10 @@
\noindent
-This assignment is about Scala and worth 10\%. The first and second
-part are due on \cwSIX{} at 11pm, and the third part on \cwSIXa{}
+This assignment is about Scala and worth 10\%. The basic
+part is due on \cwSIX{} at 11pm, and the main part on \cwSIXa{}
at 11pm. You are asked to implement two programs about list
-processing and recursion. The third part is more advanced and might
+processing and recursion. The main part is more advanced and might
include material you have not yet seen in the first lecture.
\bigskip
@@ -33,8 +33,9 @@
Like the C++ assignments, the Scala assignments will work like this: you
push your files to GitHub and receive (after sometimes a long delay) some
automated feedback. In the end we take a snapshot of the submitted files and
-apply an automated marking script to them.
+apply an automated marking script to them.\medskip
+\noindent
In addition, the Scala assignments come with a reference implementation
in form of a \texttt{jar}-file. This allows you to run any test cases
on your own computer. For example you can call Scala on the command
@@ -65,24 +66,26 @@
a value in a list.\bigskip
\noindent
-\textbf{For Part 2 + 3:} useful string functions: \texttt{.startsWith(...)} for
-checking whether a string has a given prefix, \texttt{\_ ++ \_} for
-concatenating two strings; useful option functions: \texttt{.flatten}
-flattens a list of options such that it filters way all
-\texttt{None}'s, \texttt{Try(...).getOrElse ...} runs some code that
-might raise an exception---if yes, then a default value can be given;
-useful list functions: \texttt{.head} for obtaining the first element
-in a non-empty list, \texttt{.length} for the length of a
-list; \texttt{.filter(...)} for filtering out elements in a list; \texttt{.getLines.toList} for obtaining a list of lines from
-a file; \texttt{.split(",").toList} for splitting strings according to
-a comma.\bigskip
+\textbf{For Part 2:} useful string functions:
+\texttt{.startsWith(...)} for checking whether a string has a given
+prefix, \texttt{\_ ++ \_} for concatenating two strings; useful option
+functions: \texttt{.flatten} flattens a list of options such that it
+filters way all \texttt{None}'s, \texttt{Try(...).getOrElse ...} runs
+some code that might raise an exception---if yes, then a default value
+can be given; useful list functions: \texttt{.head} for obtaining the
+first element in a non-empty list, \texttt{.length} for the length of
+a list; \texttt{.filter(...)} for filtering out elements in a list;
+\texttt{.getLines.toList} for obtaining a list of lines from a file;
+\texttt{.split(",").toList} for splitting strings according to a
+comma.\bigskip
\noindent
-Fortunately Scala supports operator overloading. But make sure you understand the difference between \texttt{100 / 3} and
+\textbf{Note!} Fortunately Scala supports operator overloading. But
+make sure you understand the difference between \texttt{100 / 3} and
\texttt{100.0 / 3}!
\newpage
-\subsection*{Part 1 (3 Marks, file collatz.scala)}
+\subsection*{Basic Part (3 Marks, file collatz.scala)}
This part is about recursion. You are asked to implement a Scala
program that tests examples of the \emph{$3n + 1$-conjecture}, also
@@ -97,8 +100,8 @@
\end{itemize}
\noindent
-For example if you start with $6$, or $9$, you obtain the
-series
+For example if you start with, say, $6$ and $9$, you obtain the
+two series
\[
\begin{array}{@{}l@{\hspace{5mm}}l@{}}
@@ -115,7 +118,7 @@
particular numbers, it is an interesting open problem to
\emph{prove} that the conjecture is true for \emph{all} numbers ($>
0$). Paul Erd\"o{}s, a famous mathematician you might have hard
- about, said about this conjecture: ``Mathematics may not be ready
+ about, said about this conjecture: ``Mathematics may not [yet] be ready
for such problems.'' and also offered a \$500 cash prize for its
solution. Jeffrey Lagarias, another mathematician, claimed that
based only on known information about this problem, ``this is an
@@ -165,7 +168,7 @@
-\subsection*{Part 2 (3 Marks, file drumb.scala)}
+\subsection*{Main Part (7 Marks, file drumb.scala)}
A purely fictional character named Mr T.~Drumb inherited in 1978
approximately 200 Million Dollar from his father. Mr Drumb prides
@@ -191,12 +194,12 @@
the stocks from our portfolio (there might be more stocks available,
if companies from our portfolio got listed in that year, or less if
some companies went bust or were de-listed).
-\item We do this for 40 years until January 2018 and check what would
+\item We do this for 40 years until January 2019 and check what would
have become out of our \$100.
\end{itemize}
\noindent
-Until Yahoo was bought by Altaba last year, historical stock market
+Until Yahoo was bought by Altaba a few years ago, historical stock market
data for such back-of-the-envelope calculations was freely available
online. Unfortunately nowadays this kind of data is more difficult to
obtain, unless you are prepared to pay extortionate prices or be
@@ -242,18 +245,21 @@
(first line), 2011 (second line) and 2012 (third line) you obtain:
\begin{verbatim}
- List(List(Some(311.349976), Some(20.544939)),
- List(Some(300.222351), Some(31.638695)),
- List(Some(330.555054), Some(39.478039)))
+ List(List(Some(312.204773), Some(26.782711)),
+ List(Some(301.0466), Some(41.244694)),
+ List(Some(331.462585), Some(51.464207)))
\end{verbatim}\hfill[1 Mark]
-\end{itemize}
+
+
+%\end{itemize}
-\subsection*{Advanced Part 3 (4 Marks, continue in file drumb.scala)}
+%\subsection*{Advanced Part 3 (4 Marks, continue in file drumb.scala)}
+%
+%\noindent
+%\textbf{Tasks}
-\noindent
-\textbf{Tasks}
+%\begin{itemize}
-\begin{itemize}
\item[(4)] Write a function that calculates the \emph{change factor} (delta)
for how a stock price has changed from one year to the next. This is
only well-defined, if the corresponding company has been traded in both
@@ -268,19 +274,19 @@
\texttt{None}.\mbox{}\hfill\mbox{[1 Mark]}
\item[(5)] Write a function that calculates all change factors
- (deltas) for the prices we obtained under Part 2. For the running
+ (deltas) for the prices we obtained in Task (2). For the running
example of Google and Apple for the years 2010 to 2012 you should
obtain 4 change factors:
-\begin{verbatim}
- List(List(Some(-0.03573992567129673), Some(0.539975124774038))
- List(Some(0.10103412653643493), Some(0.24777709700099845)))
+\begin{verbatim}
+ List(List(Some(-0.03573991804411003), Some(0.539974575389325)),
+ List(Some(0.10103414222249969), Some(0.24777764141006836)))
\end{verbatim}
That means Google did a bit badly in 2010, while Apple did very well.
Both did OK in 2011. Make sure you handle the cases where a company is
not listed in a year. In such cases the change factor should be \texttt{None}
- (see~(4)).
+ (recall Task~(4)).
\mbox{}\hfill\mbox{[1 Mark]}
\item[(6)] Write a function that calculates the ``yield'', or
@@ -289,12 +295,12 @@
no company from our portfolio existed in that year, the balance is
unchanged. Otherwise we invest in each existing company an equal
amount of our balance. Using the change factors computed under Task
- 2, calculate the new balance. Say we had \$100 in 2010, we would have
+ (2), calculate the new balance. Say we had \$100 in 2010, we would have
received in our running example involving Google and Apple:
\begin{verbatim}
- $50 * -0.03573992567129673 + $50 * 0.539975124774038
- = $25.21175995513706
+ $50 * -0.03573991804411003 + $50 * 0.539974575389325
+ = $25.21173286726075
\end{verbatim}
as profit for that year, and our new balance for 2011 is \$125 when
@@ -314,9 +320,9 @@
collected from the S\&P 500, one for blue-chip companies, including
Facebook, Amazon and Baidu; and another for listed real-estate
companies, whose names I have never heard of. Following the dumb
-investment strategy from 1978 until 2018 would have turned a starting
-balance of \$100 into roughly \$101,589 for real estate and a whopping
-\$1,587,528 for blue chips. Note when comparing these results with your
+investment strategy from 1978 until 2019 would have turned a starting
+balance of \$100 into roughly \$39,162 for real estate and a whopping
+\$462,199 for blue chips. Note when comparing these results with your
own calculations: there might be some small rounding errors, which
when compounded lead to moderately different values.\bigskip