Last active
June 1, 2017 13:57
-
-
Save seungwonpark/885feaa25fcb0944f9f6733c4c1e00f5 to your computer and use it in GitHub Desktop.
3n+1
This file contains 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
\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