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 ] sentences["all"] = [ line.replace("*","") for line in stripped ] 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): #new, oben mehr space, Strich länger und \small removed return fr"""\vspace{{1cm}} \rule{{4.5cm}}{{0.15mm}} \, \vspace{{.3cm}} \newline {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) ] prompts = [ *random.sample(sentences["all"], num_total) ] 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(8) print("Done!")