Implement bingo generator

This commit is contained in:
Dominic Zimmer 2022-08-26 10:44:35 +02:00
commit 9ddc6171c7
6 changed files with 171 additions and 0 deletions

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
*.pdf
*.aux
*.log
*.fls
*.fdb_latexmk
**/build/*
__pycache__

6
bingo/Makefile Normal file
View File

@ -0,0 +1,6 @@
all:
python generate_bingo.py
(cd build; latexmk -pdf; pdfjam --nup 1x2 --outfile output.pdf *.pdf)
template:
pdflatex template.tex

0
bingo/build/.gitkeep Normal file
View File

51
bingo/generate_bingo.py Normal file
View File

@ -0,0 +1,51 @@
import random
from functools import reduce
from tex_template import latex_template # tex_template.py
output_dir = "build/"
num_total = 9
num_hard = 3
num_easy = num_total - num_hard
sentences = {"easy": [], "hard": []}
with open("prompts.txt") as f:
raw_sentences = f.readlines()
stripped = "".join(raw_sentences).strip().split("\n")
sentences["easy"] = [ line for line in stripped if "*" not in line ]
sentences["hard"] = [ line.replace("*","") for line in stripped if "*" in line ]
print(f"[INFO] Found {len(sentences['easy'])} easy prompts")
print(f"[INFO] Found {len(sentences['hard'])} hard prompts")
""" Postprocess the content string to look nice in the latex tabular cell """
def make_cell(content: str):
return fr"""\vspace{{0.5cm}}
\rule{{3cm}}{{0.15mm}} \, \newline \small {content}
\vspace{{0.5cm}}"""
def substitute_texts(text: str, substitutions: list[str]):
return reduce( \
# reducer
lambda acc, value: acc.replace(f"[[text{value}]]", make_cell(substitutions[value])), \
# list
range(len(substitutions)), \
# initializer
text \
)
def gen_board(num: int = 1):
print(f"Generating {num} boards")
for i in range(1, num+1):
prompts = [ *random.sample(sentences["easy"], num_easy), *random.sample(sentences["hard"], num_hard) ]
random.shuffle(prompts)
pick = substitute_texts(latex_template, prompts)
filename = "output.tex" if num == 1 else f"output{i}.tex"
with open(output_dir + filename,"w") as f:
f.writelines(pick)
gen_board(36)

49
bingo/prompts.txt Normal file
View File

@ -0,0 +1,49 @@
ist mit Ludmilla verwandt
ist mit Karl verwandt
ist jünger als Ludmilla
spricht mindestens drei Sprachen
kann Schach spielen
konnte \newline $\int_{5}^{8} (2x + 1) \text{dx} = \quad $ \newline ausrechnen*
s Name hat weniger als 5 Buchstaben
reiste weiter als 100km an
(hat) studiert, aber nicht Informatik oder Computerlinguistik*
hat keine Geschwister
ist single
konnte drei Star Wars Charaktere nennen
konnte fünf Animes nennen
hat blaue Augen
konnte 15 Sekunden auf einem Bein stehen
ist veganer
ist im Saarland geboren
spielt ein Instrument
hat ein Haustier
benutzt als Betriebssystem Linux
kennt Ludmilla schon länger als zehn Jahre
kennt Karl schon länger als zehn Jahre
kannte mich nicht, hat aber ein Selfie mit mir gemacht
schlug den Bräutigam im Armdrücken
ist Linkshänder
kann eine Krawatte binden
hat ein Tattoo
trinkt keinen Kaffee
hat schonmal ein Pokémon-Spiel gespielt
hat heute schon Bier getrunken
ist größer als Karl
konnte vor meinen Augen einen Zauberwürfel lösen*
war schonmal in der Natur klettern*
hatte dieses Jahr Corona :-(
kann 5km unter 30 Minuten laufen
identifiziert sich als Ravenclaw (Harry Potter Haus)*
mag Katzen mehr als Hunde
kann Stricken
hat schonmal ein Buch von Mark-Uwe Kling gelesen
aß noch nie in der Mensa der UdS
war schonmal auf einem Musikfestival
hat eine Lebensmittelunverträglichkeit
hat außerhalb von Saarbrücken studiert*
fuhr an einem Tag mehr als 100km mit dem Fahrrad*
besitzt ein Auto
war schonmal auf Mallorca
hat mal in einer WG gewohnt
war schonmal in der Zeitung*
hat schonmal in einem Theaterstück mitgespielt*

58
bingo/tex_template.py Normal file
View File

@ -0,0 +1,58 @@
latex_template=r"""
\documentclass{article}
\pagenumbering{gobble}
\usepackage{array}
\usepackage[a5paper,landscape,margin=0.0in]{geometry}
\usepackage{graphics}
\usepackage{amsmath}
\usepackage{eurosym}
\begin{document}
\setlength\tabcolsep{1cm}
\hspace{0pt}
\vfill
\begin{center}
{\Huge Hochzeits-Bingo}
\vspace{0.2cm}
Trage in jedem Feld den Namen einer Person ein, die die genannte Eigenschaft erfüllt.
Jede Person darf nur \\ einmal eingetragen werden.
Für jedes vollständig ausgefüllte Bingo das bei Dominic oder Jan abgegeben wird \\ bekommt das Brautpaar 2 \euro.
\vfill
\resizebox{15cm}{!}{
% \begin{tabular}{|m{4cm}|m{4cm}|m{4cm}|}
\begin{tabular}{| >{\centering\arraybackslash}m{1in} | >{\centering\arraybackslash}m{1in} | >{\centering\arraybackslash}m{1in} |}
\hline \centering
[[text0]]
& \centering
[[text1]]
&
[[text2]]
\\
\hline
[[text3]]
& \centering
[[text4]]
&
[[text5]]
\\
\hline
[[text6]]
& \centering
[[text7]]
&
[[text8]]
\\
\hline
\end{tabular}
}
\end{center}
\vfill
\hspace{0pt}
\end{document}
"""