Created
August 15, 2010 00:12
-
-
Save linki/524874 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\usepackage{algorithm} | |
\usepackage{algorithmic} | |
\usepackage{amssymb} | |
\algsetup{indent=2em} | |
\newcommand{\factorial}{\ensuremath{\mbox{\sc Factorial}}} | |
\newcommand{\emit}{\ensuremath{\mbox{\sc Emit}}} | |
\begin{algorithm}[h!] \caption{$\factorial(n)$}\label{alg:factorial} \begin{algorithmic}[1] | |
\REQUIRE An integer $n \geq 0$. \ENSURE The value of $n!$. | |
\medskip | |
\FORALL{$\langle i,spoc \rangle \in \lbrack \langle i_0,spoc_0 \rangle \dots \langle i_n,spoc_n \rangle \rbrack$} | |
\STATE $\emit(\langle o,0 \rangle, 1)$ | |
\STATE $\emit(\langle o,1 \rangle, s)$ | |
\ENDFOR | |
\end{algorithmic} | |
\end{algorithm} | |
\algsetup{indent=2em} | |
\begin{algorithm}[h!] \caption{$\factorial(n)$}\label{alg:factorial2} \begin{algorithmic}[1] | |
\REQUIRE An integer $n \geq 0$. \ENSURE The value of $n!$. | |
\medskip | |
\FORALL{$\langle s \rangle \in \lbrack s_0 \dots s_n \rbrack$} | |
\IF {$s \in \mathbb N$} \STATE $sum += s$ | |
\ELSE \STATE $\emit(s, \langle o,sum \rangle)$ | |
\ENDIF | |
\ENDFOR | |
\end{algorithmic} | |
\end{algorithm} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment