Skip to content

Instantly share code, notes, and snippets.

@shackra
Last active May 6, 2024 02:47
Show Gist options
  • Save shackra/818d9a3dc93d13d19b8998086a3a88cc to your computer and use it in GitHub Desktop.
Save shackra/818d9a3dc93d13d19b8998086a3a88cc to your computer and use it in GitHub Desktop.
Generate the multiplication tables from 2 to 19 in LaTeX notation for RemNote
#!/usr/bin/env python3
results: dict[int, list[int]] = {}
for i in range(2, 20):
for j in range(2, 20):
result = i * j
operands = [i, j]
operands.sort()
if result in results:
if results[result].count(operands) == 0:
results[result].append(operands)
else:
results[result] = [operands]
all_keys = list(results.keys())
all_keys.sort()
for k in all_keys:
operands = results[k]
text = []
for operand in operands:
text.append("$%d\\times %d$" % (operand[0], operand[1]))
print("-", ", ".join(text), f">> ${k}$")
# prints the following:
# ...
# - $2\times 5$ >> $10$
# - $2\times 6$, $3\times 4$ >> $12$
# - $2\times 7$ >> $14$
# - $3\times 5$ >> $15$
# - $2\times 8$, $4\times 4$ >> $16$
# - $2\times 9$, $3\times 6$ >> $18$
# - $2\times 10$, $4\times 5$ >> $20$
# - $3\times 7$ >> $21$
# - $2\times 11$ >> $22$
# - $2\times 12$, $3\times 8$, $4\times 6$ >> $24$
# - $5\times 5$ >> $25$
# - $2\times 13$ >> $26$
# - $3\times 9$ >> $27$
# - $2\times 14$, $4\times 7$ >> $28$
# - $2\times 15$, $3\times 10$, $5\times 6$ >> $30$
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment