Skip to content

Instantly share code, notes, and snippets.

@objmagic
Created December 30, 2015 06:07
Show Gist options
  • Select an option

  • Save objmagic/94e6fd2311338d9bf45b to your computer and use it in GitHub Desktop.

Select an option

Save objmagic/94e6fd2311338d9bf45b to your computer and use it in GitHub Desktop.
LaTeX is Turing complete
\newcount \temp \newcount \fone \newcount \ftwo \newcount \counter
\newcommand{\fibonacci}[1]{
\counter=#1
\fone=1
\ftwo=1
\temp=0
\the\fone, \the\ftwo
\fibloop
}
\newcommand{\fibloop}{,
\let\next= \fibloop
\temp=\fone
\fone=\ftwo
\advance \ftwo by \temp
\ifnum \counter=0 \let\next=\relax \else \advance \counter by -1 \fi
\the\ftwo
\next
}
\documentclass[a4paper]{article}
\setlength{\parindent}{0pt}
\setlength{\oddsidemargin}{0pt}
\setlength{\topmargin}{0pt}
\begin{document}
\fibonacci{10}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment