$\mathbf{Algorithm}\ \Fart(n)\mathrm{:}$
$\mathbf{if}\ n = 0\ \mathrm{or}\ n = 1$
$\mathbf{then}\ \text{eat one can of beans}$
$\mathbf{else}\ \mathbf{if}\ n\ \mathrm{is}\ \mathrm{even}$
$\elsesp \mathbf{then}\ \text{fart once};$
$\elsesp \thensp \Fart \left( n \middle/ 2 \right)$
$\elsesp \mathbf{else}\ \Fart(n + 1);$
$\elsesp \elsesp \text{fart once};$
$\elsesp \elsesp \Fart(n - 1)$
$\elsesp \mathbf{endif};$
$\mathbf{endif}$