aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--doc/exercises.tex38
1 files changed, 38 insertions, 0 deletions
diff --git a/doc/exercises.tex b/doc/exercises.tex
index cebff1c..23b8ef4 100644
--- a/doc/exercises.tex
+++ b/doc/exercises.tex
@@ -188,6 +188,14 @@ than or equal to a preselected number.
+\item {[\textit{30}]} \textbf{Powers of the golden ratio}
+
+Implement function that returns $\varphi^n$ rounded
+to the nearest integer, where $n$ is the input and
+$\varphi$ is the golden ratio.
+
+
+
\end{enumerate}
@@ -477,5 +485,35 @@ the set of pseudoprimes.
+\item \textbf{Powers of the golden ratio}
+
+This was an information gathering exercise.
+For $n \ge 1$, $L_n = [\varphi^n]$, where
+$L_n$ is the $n^\text{th}$ Lucas number.
+
+\( \displaystyle{
+ L_n \stackrel{\text{\tiny{def}}}{\text{=}} \left \{ \begin{array}{ll}
+ 2 & \text{if} ~ n = 0 \\
+ 1 & \text{if} ~ n = 1 \\
+ L_{n - 1} + L_{n + 1} & \text{otherwise}
+ \end{array} \right .
+}\)
+
+\noindent
+but for efficiency and briefness, we will use
+\texttt{lucas} from \secref{sec:Lucas numbers}.
+
+\vspace{-1em}
+\begin{alltt}
+void golden_pow(z_t r, z_t p)
+\{
+ if (zsignum(p) <= 0)
+ zsetu(r, zzero(p));
+ else
+ lucas(r, p);
+\}
+\end{alltt}
+
+
\end{enumerate}