diff options
Diffstat (limited to 'Practical2/report/implementation.tex')
-rw-r--r-- | Practical2/report/implementation.tex | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Practical2/report/implementation.tex b/Practical2/report/implementation.tex new file mode 100644 index 0000000..cc8a940 --- /dev/null +++ b/Practical2/report/implementation.tex @@ -0,0 +1,19 @@ +\section{Implementation} +\label{sec:implementation} + +A C implementation accompanies this report. The $\PR$ function is implemented in $\pazocal O(1)$ in \mintinline{c}{round_profit}, but is not shown here for the sake of brevity. + +The implementation of the $\PP$ function, \mintinline{c}{maximum_profit}, follows the flow of \autoref{alg:maximum-profit-optimised}. However, it was easier to take the optimisation of \autoref{lem:divide-by-5} out of this function and apply it when reading in the input sequence. + +\inputminted[fontsize=\footnotesize,linenos,firstline=17,lastline=48]{c}{../checkout.c} + +In the \mintinline{c}{main} function we see how \autoref{lem:divide-by-5} can be applied. In the last line we also see how the minimal sum may be computed from the maximum profit. + +\inputminted[fontsize=\footnotesize,linenos,firstline=50,lastline=67]{c}{../checkout.c} + +\subsection{Compilation} +\label{sec:implementation:compilation} +Optimal results are achieved with \texttt{clang}, which is on average $25\%$ faster than \texttt{gcc}. In any case, the \texttt{-Ofast} flag should be used. It speeds up the program with a factor $4$ in the case of \texttt{clang} and a factor $3$ in the case of \texttt{gcc}. + +A Makefile accompanies the C code. If you don't have \texttt{clang} installed, you should install it. If you don't want to install it, use \mintinline{bash}{make CC=gcc}. + |