From c0d2a2755c4f72738360030f0d7c2b941f61e8a1 Mon Sep 17 00:00:00 2001 From: lukew3 Date: Thu, 17 Dec 2020 18:58:01 -0500 Subject: [PATCH] Added latex for 11, 12, and 17. First 3 of algebra section --- mathgenerator/funcs/algebra/basic_algebra.py | 10 +++++-- mathgenerator/funcs/algebra/log.py | 11 ++++++-- .../algebra/multiply_int_to_22_matrix.py | 28 +++++++++++++++++-- test.py | 14 +--------- 4 files changed, 41 insertions(+), 22 deletions(-) diff --git a/mathgenerator/funcs/algebra/basic_algebra.py b/mathgenerator/funcs/algebra/basic_algebra.py index 0626cf8..2d0a3fb 100644 --- a/mathgenerator/funcs/algebra/basic_algebra.py +++ b/mathgenerator/funcs/algebra/basic_algebra.py @@ -1,7 +1,7 @@ from .__init__ import * -def basicAlgebraFunc(maxVariable=10): +def basicAlgebraFunc(maxVariable=10, style='raw'): a = random.randint(1, maxVariable) b = random.randint(1, maxVariable) c = random.randint(b, maxVariable) @@ -20,8 +20,12 @@ def basicAlgebraFunc(maxVariable=10): elif a == 1 or a == i: x = f"{c - b}" - problem = f"{a}x + {b} = {c}" - solution = x + if style == 'latex': + problem = f"\\({a}x + {b} = {c}\\)" + solution = "\\(" + x + "\\)" + else: + problem = f"{a}x + {b} = {c}" + solution = x return problem, solution diff --git a/mathgenerator/funcs/algebra/log.py b/mathgenerator/funcs/algebra/log.py index bc147f2..8bcc16d 100644 --- a/mathgenerator/funcs/algebra/log.py +++ b/mathgenerator/funcs/algebra/log.py @@ -1,13 +1,18 @@ from .__init__ import * -def logFunc(maxBase=3, maxVal=8): +def logFunc(maxBase=3, maxVal=8, style='raw'): a = random.randint(1, maxVal) b = random.randint(2, maxBase) c = pow(b, a) - problem = "log" + str(b) + "(" + str(c) + ")" - solution = str(a) + if style == 'latex': + problem = "\\(\\log_{" + str(b) + "}" + str(c) + "\\)" + print(problem) + solution = "\\(" + str(a) + "\\)" + else: + problem = "log" + str(b) + "(" + str(c) + ")" + solution = str(a) return problem, solution diff --git a/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py b/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py index 3d79834..4cc0d5b 100644 --- a/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py +++ b/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py @@ -1,15 +1,37 @@ from .__init__ import * -def multiplyIntToMatrix22(maxMatrixVal=10, maxRes=100): +def multiplyIntToMatrix22(maxMatrixVal=10, maxRes=100, style='raw'): a = random.randint(0, maxMatrixVal) b = random.randint(0, maxMatrixVal) c = random.randint(0, maxMatrixVal) d = random.randint(0, maxMatrixVal) constant = random.randint(0, int(maxRes / max(a, b, c, d))) - problem = f"{constant} * [[{a}, {b}], [{c}, {d}]] = " - solution = f"[[{a*constant},{b*constant}],[{c*constant},{d*constant}]]" + + a1 = a * constant + b1 = b * constant + c1 = c * constant + d1 = d * constant + + if style == 'latex': + problem = ("\\(" + str(constant) + "\\cdot" + + "\\begin{bmatrix}" + + str(a) + "&" + str(b) + "\\\\" + + str(c) + "&" + str(d) + + "\end{bmatrix}=" + + "\\)" + ) + solution = ("\\(" + + "\\begin{bmatrix}" + + str(a1) + "&" + str(b1) + "\\\\" + + str(c1) + "&" + str(d1) + + "\end{bmatrix}" + + "\\)" + ) + else: + problem = f"{constant} * [[{a}, {b}], [{c}, {d}]] = " + solution = f"[[{a1},{b1}],[{c1},{d1}]]" return problem, solution diff --git a/test.py b/test.py index 33ca0af..1a538e2 100644 --- a/test.py +++ b/test.py @@ -1,15 +1,3 @@ from mathgenerator import mathgen -# test your generators here - -# print(mathgen.addition()) - -# prints each generator in genList -# list = mathgen.getGenList() -#for item in list: -# print(item[2]) - -# print(mathgen.getGenList()) - -print(mathgen.genById(0, maxSum=20, style='latex')[0]) -print(mathgen.genById(1, style='latex')) +print(mathgen.genById(17, style='latex'))