Euklidischer-Algorithmus.tex 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. \documentclass{article}
  2. \usepackage[pdftex,active,tightpage]{preview}
  3. \setlength\PreviewBorder{2mm}
  4. \usepackage[utf8]{inputenc} % this is needed for umlauts
  5. \usepackage[ngerman]{babel} % this is needed for umlauts
  6. \usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf
  7. \usepackage{amssymb,amsmath,amsfonts} % nice math rendering
  8. \usepackage{braket} % needed for \Set
  9. \usepackage{algorithm,algpseudocode}
  10. \usepackage{tikz}
  11. \usetikzlibrary{decorations.pathreplacing,calc}
  12. \newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
  13. \newcommand*{\AddNote}[4]{%
  14. \begin{tikzpicture}[overlay, remember picture]
  15. \draw [decoration={brace,amplitude=0.5em},decorate,very thick]
  16. ($(#3)!(#1.north)!($(#3)-(0,1)$)$) --
  17. ($(#3)!(#2.south)!($(#3)-(0,1)$)$)
  18. node [align=center, text width=2.5cm, pos=0.5, anchor=west] {#4};
  19. \end{tikzpicture}
  20. }%
  21. \begin{document}
  22. \begin{preview}
  23. \begin{algorithm}[H]
  24. \begin{algorithmic}
  25. \Require $Z \in \mathbb{R}_{\geq 0}, b \in \mathbb{N}_{\geq 2}$
  26. \State $p\gets 0$\tikzmark{top}
  27. \While{$b^p > Z$}\tikzmark{right}
  28. \State $p\gets p+1$
  29. \EndWhile
  30. \State $i\gets p-1$\tikzmark{bottom}
  31. \\
  32. \While{$Z \neq 0$}\tikzmark{top2}
  33. \State $y_i\gets Z\,\mbox{div}\, b^i$
  34. \State $R\gets Z\,\mbox{mod}\, b^i$
  35. \State $Z\gets R$
  36. \State $i\gets i-1$
  37. \EndWhile\tikzmark{bottom2}
  38. \\
  39. \State \textbf{Result:} $y_{p-1} y_{p-2} \dots y_0, y_{-1} \dots y_{i+1}$
  40. \end{algorithmic}
  41. \caption{Euclidean algorithm for changing base from base 10}
  42. \AddNote{top}{bottom}{right}{calclulate $p$ such that: $b^p \leq Z < b^{p+1}$}
  43. \AddNote{top2}{bottom2}{right}{Calculate one digit in every loop}
  44. \label{alg:euclidBaseTransformation}
  45. \end{algorithm}
  46. \end{preview}
  47. \end{document}