📚 The CoCalc Library - books, templates and other resources
cocalc-examples / martinthoma-latex-examples / source-code / Pseudocode / Euklidischer-Algorithmus / Euklidischer-Algorithmus.tex
132930 viewsLicense: OTHER
\documentclass{article}1\usepackage[pdftex,active,tightpage]{preview}2\setlength\PreviewBorder{2mm}34\usepackage[utf8]{inputenc} % this is needed for umlauts5\usepackage[ngerman]{babel} % this is needed for umlauts6\usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf7\usepackage{amssymb,amsmath,amsfonts} % nice math rendering8\usepackage{braket} % needed for \Set9\usepackage{algorithm,algpseudocode}1011\usepackage{tikz}12\usetikzlibrary{decorations.pathreplacing,calc}13\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}14\newcommand*{\AddNote}[4]{%15\begin{tikzpicture}[overlay, remember picture]16\draw [decoration={brace,amplitude=0.5em},decorate,very thick]17($(#3)!(#1.north)!($(#3)-(0,1)$)$) --18($(#3)!(#2.south)!($(#3)-(0,1)$)$)19node [align=center, text width=2.5cm, pos=0.5, anchor=west] {#4};20\end{tikzpicture}21}%2223\begin{document}24\begin{preview}25\begin{algorithm}[H]26\begin{algorithmic}27\Require $Z \in \mathbb{R}_{\geq 0}, b \in \mathbb{N}_{\geq 2}$28\State $p\gets 0$\tikzmark{top}29\While{$b^p > Z$}\tikzmark{right}30\State $p\gets p+1$31\EndWhile32\State $i\gets p-1$\tikzmark{bottom}33\\34\While{$Z \neq 0$}\tikzmark{top2}35\State $y_i\gets Z\,\mbox{div}\, b^i$36\State $R\gets Z\,\mbox{mod}\, b^i$37\State $Z\gets R$38\State $i\gets i-1$39\EndWhile\tikzmark{bottom2}40\\41\State \textbf{Result:} $y_{p-1} y_{p-2} \dots y_0, y_{-1} \dots y_{i+1}$42\end{algorithmic}43\caption{Euclidean algorithm for changing base from base 10}44\AddNote{top}{bottom}{right}{calclulate $p$ such that: $b^p \leq Z < b^{p+1}$}45\AddNote{top2}{bottom2}{right}{Calculate one digit in every loop}46\label{alg:euclidBaseTransformation}47\end{algorithm}48\end{preview}49\end{document}505152