From 802b2b18704f1b04ab3c3195d49333a546dc0ff4 Mon Sep 17 00:00:00 2001
From: Mattias Andrée <maandree@kth.se>
Date: Mon, 25 Jul 2016 15:13:29 +0200
Subject: Add exercise: [30] Powers of the golden ratio
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Mattias Andrée <maandree@kth.se>
---
 doc/exercises.tex | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

(limited to 'doc/exercises.tex')

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}
-- 
cgit v1.2.3-70-g09d2

