| changeset 498 | 0f1b97538ad4 |
| parent 471 | 31b81f20fd9a |
| child 501 | 3717785f2c37 |
| 497:ef37fb04a343 | 498:0f1b97538ad4 |
|---|---|
6 |
6 |
7 |
7 |
8 |
8 |
9 \begin{document} |
9 \begin{document} |
10 |
10 |
11 \section*{Core Part 1 (Scala, 3 Marks)} |
11 \section*{Core Part 1 (Scala, 1.5 Marks)} |
12 |
12 |
13 \mbox{}\hfill\textit{``The most effective debugging tool is still careful thought,}\\ |
13 \mbox{}\hfill\textit{``The most effective debugging tool is still careful thought,}\\ |
14 \mbox{}\hfill\textit{coupled with judiciously placed print statements.''}\smallskip\\ |
14 \mbox{}\hfill\textit{coupled with judiciously placed print statements.''}\smallskip\\ |
15 \mbox{}\hfill\textit{ --- Brian W. Kernighan, in Unix for Beginners (1979)}\bigskip |
15 \mbox{}\hfill\textit{ --- Brian W. Kernighan, in Unix for Beginners (1979)}\bigskip |
16 |
16 |
60 a value in a list.\bigskip |
60 a value in a list.\bigskip |
61 |
61 |
62 |
62 |
63 |
63 |
64 \newpage |
64 \newpage |
65 \subsection*{Core Part 1 (3 Marks, file collatz.scala)} |
65 \subsection*{Core Part 1 (1.5 Marks, file collatz.scala)} |
66 |
66 |
67 This part is about function definitions and recursion. You are asked |
67 This part is about function definitions and recursion. You are asked |
68 to implement a Scala program that tests examples of the |
68 to implement a Scala program that tests examples of the |
69 \emph{$3n + 1$-conjecture}, also called \emph{Collatz |
69 \emph{$3n + 1$-conjecture}, also called \emph{Collatz |
70 conjecture}.\video{https://www.youtube.com/watch?v=LqKpkdRRLZw} |
70 conjecture}.\video{https://www.youtube.com/watch?v=LqKpkdRRLZw} |
116 case of starting with $9$, it takes $19$ (see above). We assume it |
116 case of starting with $9$, it takes $19$ (see above). We assume it |
117 takes $0$ steps, if we start with $1$. In order to |
117 takes $0$ steps, if we start with $1$. In order to |
118 try out this function with large numbers, you should use |
118 try out this function with large numbers, you should use |
119 \texttt{Long} as argument type, instead of \texttt{Int}. You can |
119 \texttt{Long} as argument type, instead of \texttt{Int}. You can |
120 assume this function will be called with numbers between $1$ and |
120 assume this function will be called with numbers between $1$ and |
121 $1$ Million. \hfill[1 Mark] |
121 $1$ Million. \hfill[0.5 Marks] |
122 |
122 |
123 \item[(2)] Write a second function that takes an upper bound as |
123 \item[(2)] Write a second function that takes an upper bound as |
124 an argument and calculates the steps for all numbers in the range from |
124 an argument and calculates the steps for all numbers in the range from |
125 1 up to this bound (the bound including). It returns the maximum number of |
125 1 up to this bound (the bound including). It returns the maximum number of |
126 steps and the corresponding number that needs that many steps. More |
126 steps and the corresponding number that needs that many steps. More |
127 precisely it returns a pair where the first component is the number |
127 precisely it returns a pair where the first component is the number |
128 of steps and the second is the corresponding number. \hfill\mbox{[1 |
128 of steps and the second is the corresponding number. \hfill\mbox{[0.5 |
129 Mark]} |
129 Marks]} |
130 |
130 |
131 \item[(3)] Write a function that calculates \emph{hard |
131 \item[(3)] Write a function that calculates \emph{hard |
132 numbers} \here{https://medium.com/cantors-paradise/the-collatz-conjecture-some-shocking-results-from-180-000-iterations-7fea130d0377} |
132 numbers} \here{https://medium.com/cantors-paradise/the-collatz-conjecture-some-shocking-results-from-180-000-iterations-7fea130d0377} |
133 in the Collatz series---these are the last odd numbers just before a |
133 in the Collatz series---these are the last odd numbers just before a |
134 power of two is reached. For this, implement an |
134 power of two is reached. For this, implement an |
147 because of the series |
147 because of the series |
148 % |
148 % |
149 \[113, 340, 170, \,\fbox{85}\,, 256, 128, 64, 32, 16, 8, 4, 2, 1\] |
149 \[113, 340, 170, \,\fbox{85}\,, 256, 128, 64, 32, 16, 8, 4, 2, 1\] |
150 |
150 |
151 The \textit{last-odd} function will only be called with numbers that are not |
151 The \textit{last-odd} function will only be called with numbers that are not |
152 powers of 2 themselves.\hfill\mbox{[1 Mark]} |
152 powers of 2 themselves.\hfill\mbox{[0.5 Mark]} |
153 \end{itemize} |
153 \end{itemize} |
154 |
154 |
155 \noindent |
155 \noindent |
156 \textbf{Test Data:} Some test cases are: |
156 \textbf{Test Data:} Some test cases are: |
157 |
157 |