Skip to content

Instantly share code, notes, and snippets.

@algon-320
Created May 9, 2017 14:13
Show Gist options
  • Save algon-320/8ec259c3afcf71240b4527b2b99cf288 to your computer and use it in GitHub Desktop.
Save algon-320/8ec259c3afcf71240b4527b2b99cf288 to your computer and use it in GitHub Desktop.
TeXでFizzBuzz
\documentclass{jarticle}
\makeatletter
\newcount \xx@res
\def\remainder#1#2{
\newcount \xx@a
\xx@a = #1
\divide \xx@a #2
\multiply \xx@a -#2
\advance \xx@a #1
\xx@res = \xx@a
}
\def\fizzbuzz#1{
\newcount \xx@remaind@three
\newcount \xx@remaind@five
\newcount \xx@n
\newcount \xx@t
\xx@n = #1
\advance \xx@n 1
\xx@t = 1
\@whilenum \xx@t < \xx@n \do {
\remainder{\xx@t}{3}
\xx@remaind@three = \xx@res
\remainder{\xx@t}{5}
\xx@remaind@five = \xx@res%
\the\xx@t :
\ifnum \xx@remaind@three = 0
\ifnum \xx@remaind@five = 0
Fizz Buzz\\
\else
Fizz\\
\fi
\else
\ifnum \xx@remaind@five = 0
Buzz\\
\else
\the\xx@t\\
\fi
\fi
\advance \xx@t 1
}
}
\makeatother
\begin{document}
FizzBuzz 30\\
\fizzbuzz{30}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment