cws/cw01.tex
changeset 306 1877cc717291
parent 284 9a04eb6a2291
child 314 21b52310bd8b
equal deleted inserted replaced
305:e745f6e1ebf6 306:1877cc717291
     4 \usepackage{disclaimer}
     4 \usepackage{disclaimer}
     5 \usepackage{../langs}
     5 \usepackage{../langs}
     6 
     6 
     7 \begin{document}
     7 \begin{document}
     8 
     8 
     9 \section*{Assignment 6 (Scala)}
     9 \section*{Part 6 (Scala)}
    10 
    10 
    11 \mbox{}\hfill\textit{``The most effective debugging tool is still careful thought,}\\
    11 \mbox{}\hfill\textit{``The most effective debugging tool is still careful thought,}\\
    12 \mbox{}\hfill\textit{coupled with judiciously placed print statements.''}\smallskip\\
    12 \mbox{}\hfill\textit{coupled with judiciously placed print statements.''}\smallskip\\
    13 \mbox{}\hfill\textit{ --- Brian W. Kernighan, in Unix for Beginners (1979)}\medskip\bigskip
    13 \mbox{}\hfill\textit{ --- Brian W. Kernighan, in Unix for Beginners (1979)}\medskip\bigskip
    14 
    14 
    15  
    15  
    16 \noindent
    16 \noindent
    17 This assignment is about Scala. You are asked to implement two programs
    17 This part is about Scala. You are asked to implement two programs
    18 about list processing and recursion. The preliminary part (3\%) is due
    18 about list processing and recursion. The preliminary part (3\%) is due
    19 on \cwSIX{} at 4pm, and the core part on \cwSIXa{} at 4pm.  The core
    19 on \cwSIX{} at 4pm, and the core part on \cwSIXa{} at 4pm.  The core
    20 part is more advanced and might include material you have not yet seen
    20 part is more advanced and might include material you have not yet seen
    21 in the first lecture.\bigskip
    21 in the first lecture.\bigskip
    22  
    22  
    34 push your files to GitHub and receive (after sometimes a long delay) some
    34 push your files to GitHub and receive (after sometimes a long delay) some
    35 automated feedback. In the end we take a snapshot of the submitted files and
    35 automated feedback. In the end we take a snapshot of the submitted files and
    36 apply an automated marking script to them.\medskip
    36 apply an automated marking script to them.\medskip
    37 
    37 
    38 \noindent
    38 \noindent
    39 In addition, the Scala assignments come with a reference implementation
    39 In addition, the Scala coursework comes with a reference implementation
    40 in form of a \texttt{jar}-file. This allows you to run any test cases
    40 in form of \texttt{jar}-files. This allows you to run any test cases
    41 on your own computer. For example you can call Scala on the command
    41 on your own computer. For example you can call Scala on the command
    42 line with the option \texttt{-cp collatz.jar} and then query any
    42 line with the option \texttt{-cp collatz.jar} and then query any
    43 function from the template file. Say you want to find out what
    43 function from the template file. Say you want to find out what
    44 the functions \texttt{collatz} and \texttt{collatz\_max}
    44 the functions \texttt{collatz} and \texttt{collatz\_max}
    45 produce: for this you just need to prefix them with the object name
    45 produce: for this you just need to prefix them with the object name
    57 \end{lstlisting}%$
    57 \end{lstlisting}%$
    58 
    58 
    59 \subsection*{Hints}
    59 \subsection*{Hints}
    60 
    60 
    61 \noindent
    61 \noindent
    62 \textbf{For Part 1:} useful math operators: \texttt{\%} for modulo; useful
    62 \textbf{For Preliminary Part:} useful math operators: \texttt{\%} for modulo; useful
    63 functions: \mbox{\texttt{(1\,to\,10)}} for ranges, \texttt{.toInt},
    63 functions: \mbox{\texttt{(1\,to\,10)}} for ranges, \texttt{.toInt},
    64 \texttt{.toList} for conversions, \texttt{List(...).max} for the
    64 \texttt{.toList} for conversions, \texttt{List(...).max} for the
    65 maximum of a list, \texttt{List(...).indexOf(...)} for the first index of
    65 maximum of a list, \texttt{List(...).indexOf(...)} for the first index of
    66 a value in a list.\bigskip
    66 a value in a list.\bigskip
    67 
    67 
    68 \noindent
    68 \noindent
    69 \textbf{For Part 2:} useful string functions:
    69 \textbf{For Core Part:} useful string functions:
    70 \texttt{.startsWith(...)} for checking whether a string has a given
    70 \texttt{.startsWith(...)} for checking whether a string has a given
    71 prefix, \texttt{\_ ++ \_} for concatenating two strings; useful option
    71 prefix, \texttt{\_ ++ \_} for concatenating two strings; useful option
    72 functions: \texttt{.flatten} flattens a list of options such that it
    72 functions: \texttt{.flatten} flattens a list of options such that it
    73 filters way all \texttt{None}'s, \texttt{Try(...).getOrElse ...} runs
    73 filters way all \texttt{None}'s, \texttt{Try(...).getOrElse ...} runs
    74 some code that might raise an exception---if yes, then a default value
    74 some code that might raise an exception---if yes, then a default value
   115 curiously they seem to always terminate in $1$. The conjecture is that
   115 curiously they seem to always terminate in $1$. The conjecture is that
   116 this will \emph{always} happen for every number greater than
   116 this will \emph{always} happen for every number greater than
   117 0.\footnote{While it is relatively easy to test this conjecture with
   117 0.\footnote{While it is relatively easy to test this conjecture with
   118   particular numbers, it is an interesting open problem to
   118   particular numbers, it is an interesting open problem to
   119   \emph{prove} that the conjecture is true for \emph{all} numbers ($>
   119   \emph{prove} that the conjecture is true for \emph{all} numbers ($>
   120   0$). Paul Erd\"o{}s, a famous mathematician you might have hard
   120   0$). Paul Erd\"o{}s, a famous mathematician you might have heard
   121   about, said about this conjecture: ``Mathematics may not [yet] be ready
   121   about, said about this conjecture: ``Mathematics may not [yet] be ready
   122   for such problems.'' and also offered a \$500 cash prize for its
   122   for such problems.'' and also offered a \$500 cash prize for its
   123   solution. Jeffrey Lagarias, another mathematician, claimed that
   123   solution. Jeffrey Lagarias, another mathematician, claimed that
   124   based only on known information about this problem, ``this is an
   124   based only on known information about this problem, ``this is an
   125   extraordinarily difficult problem, completely out of reach of
   125   extraordinarily difficult problem, completely out of reach of
   186   or some Real Estate stocks.
   186   or some Real Estate stocks.
   187 \item If some of the stocks in our portfolio are traded in January of
   187 \item If some of the stocks in our portfolio are traded in January of
   188   a year, we invest our money in equal amounts in each of these
   188   a year, we invest our money in equal amounts in each of these
   189   stocks.  For example if we have \$100 and there are four stocks that
   189   stocks.  For example if we have \$100 and there are four stocks that
   190   are traded in our portfolio, we buy \$25 worth of stocks
   190   are traded in our portfolio, we buy \$25 worth of stocks
   191   from each. Be careful to also test cases where you trade with 3 stocks, for example. 
   191   from each. (Be careful to also test cases where you trade with 3 stocks.) 
   192 \item Next year in January, we look at how our stocks did, liquidate
   192 \item Next year in January, we look at how our stocks did, liquidate
   193   everything, and re-invest our (hopefully) increased money in again
   193   everything, and re-invest our (hopefully) increased money in again
   194   the stocks from our portfolio (there might be more stocks available,
   194   the stocks from our portfolio (there might be more stocks available,
   195   if companies from our portfolio got listed in that year, or less if
   195   if companies from our portfolio got listed in that year, or less if
   196   some companies went bust or were de-listed).
   196   some companies went bust or were de-listed).
   201 \noindent
   201 \noindent
   202 Until Yahoo was bought by Altaba a few years ago, historical stock market
   202 Until Yahoo was bought by Altaba a few years ago, historical stock market
   203 data for such back-of-the-envelope calculations was freely available
   203 data for such back-of-the-envelope calculations was freely available
   204 online. Unfortunately nowadays this kind of data is more difficult to
   204 online. Unfortunately nowadays this kind of data is more difficult to
   205 obtain, unless you are prepared to pay extortionate prices or be
   205 obtain, unless you are prepared to pay extortionate prices or be
   206 severely rate-limited.  Therefore this assignment comes with a number
   206 severely rate-limited.  Therefore this part comes with a number
   207 of files containing CSV-lists with the historical stock prices for the
   207 of files containing CSV-lists with the historical stock prices for the
   208 companies in our portfolios. Use these files for the following
   208 companies in our portfolios. Use these files for the following
   209 tasks.\bigskip
   209 tasks.\bigskip
   210 
   210 
   211 \newpage
   211 \newpage