diff options
author | Camil Staps | 2015-12-11 13:19:52 +0000 |
---|---|---|
committer | Camil Staps | 2015-12-11 13:19:52 +0000 |
commit | 52a67a6466a4bc10f809f1fb68e2db5830c05f64 (patch) | |
tree | 14557d69017ba5ef33ec724bc0859842d7da6fcc /Practical2/report/implementation.tex | |
parent | Practical 1; samples the program fails on (diff) |
Finish first version report practical 2
Some changes were made to the code and the Makefile to clean up, make it
more in line with the algorithm as described in the report, etc. No
significant changes.
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}. + |