diff -r 9476aee44eed -r cccdae0fccc7 cws/cw01.tex --- a/cws/cw01.tex Wed Aug 12 00:56:20 2020 +0100 +++ b/cws/cw01.tex Sun Aug 23 14:39:58 2020 +0100 @@ -64,12 +64,12 @@ \newpage \subsection*{Preliminary 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 called -\emph{Collatz -conjecture}.\video{https://www.youtube.com./watch?v=LqKpkdRRLZw} This -conjecture can be described as follows: Start with any positive number -$n$ greater than $0$: +This part is about function definitions and recursion. You are asked +to implement a Scala program that tests examples of the +\emph{$3n + 1$-conjecture}, also called \emph{Collatz + conjecture}.\video{https://www.youtube.com./watch?v=LqKpkdRRLZw} +This conjecture can be described as follows: Start with any positive +number $n$ greater than $0$: \begin{itemize} \item If $n$ is even, divide it by $2$ to obtain $n / 2$. @@ -134,7 +134,7 @@ power of two is reached. For this, implement an \textit{is-power-of-two} function which tests whether a number is a power of two. The easiest way to implement this is by using the - bit-operator $\&$. For a power of two, say $n$ with $n > 0$, it + bit-operator $\&$ of Scala. For a power of two, say $n$ with $n > 0$, it holds that $n \;\&\; (n - 1)$ is equal to zero. I let you think why this is the case. The function \textit{is-hard} calculates whether $3n + 1$ is a power of two. Finally the \textit{last-odd} function @@ -151,7 +151,7 @@ \end{itemize} \noindent -\textbf{Test Data:} Some test ranges are: +\textbf{Test Data:} Some test ranges and cases are: \begin{itemize} \item 1 to 10 where $9$ takes 19 steps @@ -162,6 +162,9 @@ \item 1 to 1 Million where $837,799$ takes 524 steps %% runs out of stack space %% \item[$\bullet$] $1 - 10$ million where $8,400,511$ takes 685 steps +\item 21 is the last odd number for 84 +\item 341 is the last odd number for 201, 604, 605 and 8600 + \end{itemize}