Skip to content

Instantly share code, notes, and snippets.

@seungwonpark
Last active June 1, 2017 13:57
Show Gist options
  • Save seungwonpark/885feaa25fcb0944f9f6733c4c1e00f5 to your computer and use it in GitHub Desktop.
Save seungwonpark/885feaa25fcb0944f9f6733c4c1e00f5 to your computer and use it in GitHub Desktop.
3n+1
\documentclass{article}
\newcount\x
\newcount\i
\def\collatz#1{
\x #1 \relax
\calccollatz
}
\def\calccollatz{
\ifnum\x=1
\the\x
\else
\the\x,
\ifodd\x
\multiply\x by 3
\advance\x by 1
\else
\divide\x by 2
\fi
\calccollatz
\fi
}
\begin{document}
\i = 1
\loop\ifnum\i<11
\noindent \collatz\i \par
\advance\i by 1
\repeat
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment