Skip to content

Instantly share code, notes, and snippets.

@k16shikano
Last active May 22, 2020 10:01
Show Gist options
  • Save k16shikano/17a821bd4792c76548047b8c1154fac3 to your computer and use it in GitHub Desktop.
Save k16shikano/17a821bd4792c76548047b8c1154fac3 to your computer and use it in GitHub Desktop.
TeXでスロットマシン
% inspired by https://tex.stackexchange.com/questions/524022/switch-string-commands-based-on-random-values-to-produce-random-cards
\documentclass{article}
\usepackage{xparse}
\usepackage{scsnowman}
\usepackage{multicol}
\ExplSyntaxOn
\NewDocumentCommand{\jackpodsc}{}
{\three_snowmen:}
\int_new:N \l__total
\int_set:Nn \l__total { 1 }
\cs_new_protected:Nn \three_snowmen: {
\ints_to_snowmen:e
{ \int_to_base:nn { \int_rand:nn { 49 }{ 342 } } { 7 } }
}
\cs_new_protected:Nn \ints_to_snowmen:n {
\ints_to_snowmen:nnn #1
}
\cs_generate_variant:Nn \ints_to_snowmen:n { e }
\cs_new_protected:Nn \ints_to_snowmen:nnn {
\fcolorbox{black}{brown} {
\int_to_snowman:n #1 ~
\int_to_snowman:n #2 ~
\int_to_snowman:n #3
}
\int_compare:nTF { #1 == #2 == #3 } {
\par Jackpot ~ after ~ \int_use:N \l__total tries!
}{
\par
\int_add:Nn \l__total { 1 }
\three_snowmen:
}
}
\cs_new_protected:Nn \int_to_snowman:n {
\fcolorbox{black}{white} {
\str_case:nn { #1 } {
{ 0 }{ \scsnowman[muffler=red] }
{ 1 }{ \scsnowman[muffler=blue] }
{ 2 }{ \scsnowman[muffler=green] }
{ 3 }{ \scsnowman[muffler=yellow] }
{ 4 }{ \scsnowman[muffler=black] }
{ 5 }{ \scsnowman[muffler=orange] }
{ 6 }{ \scsnowman[hat=black] }
} }
}
\ExplSyntaxOff
\begin{document}
\begin{multicols}{3}
\jackpodsc
\end{multicols}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment