Skip to content

Instantly share code, notes, and snippets.

@rmetzler
Forked from linki/gist:524874
Created August 15, 2010 07:50
Show Gist options
  • Save rmetzler/525230 to your computer and use it in GitHub Desktop.
Save rmetzler/525230 to your computer and use it in GitHub Desktop.
\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