Skip to content

Instantly share code, notes, and snippets.

@nixeneko
Last active August 4, 2017 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nixeneko/df836b0de22ff633fdca1680a8201b89 to your computer and use it in GitHub Desktop.
Save nixeneko/df836b0de22ff633fdca1680a8201b89 to your computer and use it in GitHub Desktop.
a fizzbuzz implementation on TeX. tested on zelatex/
\documentclass[a4paper]{bxjsarticle}
\usepackage{zxjatype}
\usepackage{url}
\usepackage{here}
\usepackage{amsmath}
\usepackage{polyglossia}
%\setdefaultlanguage{english}
\setjamainfont{ipam.ttf}
\setjasansfont{ipag.ttf}
\setjamonofont{ipag.ttf}
\usepackage{xltxtra}
\usepackage{xunicode}
\setmainfont{Times New Roman}
\newfontfamily\cyrillicfont{Times New Roman}
\newfontfamily\greekfont[Script=Greek]{Times New Roman}
\setotherlanguages{greek}
\makeatletter
\def\checkfizzbuzz#1{
\newcount\n \newcount\m \newcount\t \newcount\f%
\n=#1 \m=#1 \t=#1 \f=#1%
\divide \n by 3%
\multiply \n by 3%
\advance \t by -\n%
\divide \m by 5%
\multiply \m by 5%
\advance \f by -\m%
%#1=\t\relax%
%\the\t , \the\f
\ifnum\t=0 {Fizz}\fi%
\ifnum\f=0 {Buzz}\fi%
\multiply\t by \f%
\ifnum\t>0 #1\fi%
}
\makeatother
\def\fizzbuzz#1{
\newcount\cnt \newcount\last%
\last=#1%
\advance \last by -1%
\cnt=0%
\loop\ifnum\cnt<\last%
\advance\cnt by 1%
\checkfizzbuzz{\the\cnt}, %
\repeat%
\advance\cnt by 1%
\checkfizzbuzz{\the\cnt}%
}
\begin{document}
\fizzbuzz{1000}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment