mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 06:25:23 +01:00
yapf lint
This commit is contained in:
@@ -45,10 +45,12 @@ def combine_like_terms(max_coef=10, max_exp=20, max_terms=10):
|
||||
numTerms = random.randint(1, max_terms)
|
||||
|
||||
coefs = [random.randint(1, max_coef) for _ in range(numTerms)]
|
||||
exponents = [random.randint(1, max(max_exp - 1, 2))
|
||||
for _ in range(numTerms)]
|
||||
exponents = [
|
||||
random.randint(1, max(max_exp - 1, 2)) for _ in range(numTerms)
|
||||
]
|
||||
|
||||
problem = " + ".join([f"{coefs[i]}x^{{{exponents[i]}}}" for i in range(numTerms)])
|
||||
problem = " + ".join(
|
||||
[f"{coefs[i]}x^{{{exponents[i]}}}" for i in range(numTerms)])
|
||||
d = {}
|
||||
for i in range(numTerms):
|
||||
if exponents[i] in d:
|
||||
@@ -133,9 +135,7 @@ def complex_quadratic(prob_type=0, max_range=10):
|
||||
return problem, solution
|
||||
|
||||
|
||||
def compound_interest(max_principle=10000,
|
||||
max_rate=10,
|
||||
max_time=10):
|
||||
def compound_interest(max_principle=10000, max_rate=10, max_time=10):
|
||||
r"""Compound Interest
|
||||
|
||||
| Ex. Problem | Ex. Solution |
|
||||
@@ -172,10 +172,7 @@ def distance_two_points(max_val_xy=20, min_val_xy=-20):
|
||||
return problem, solution
|
||||
|
||||
|
||||
def expanding(range_x1=10,
|
||||
range_x2=10,
|
||||
range_a=10,
|
||||
range_b=10):
|
||||
def expanding(range_x1=10, range_x2=10, range_a=10, range_b=10):
|
||||
r"""Expanding Factored Binomial
|
||||
|
||||
| Ex. Problem | Ex. Solution |
|
||||
@@ -340,10 +337,10 @@ def intersection_of_two_lines(min_m=-10,
|
||||
x = rf"\frac{{{x.numerator}}}{{{x.denominator}}}"
|
||||
return x
|
||||
|
||||
m1 = (random.randint(min_m,
|
||||
max_m), random.randint(min_denominator, max_denominator))
|
||||
m2 = (random.randint(min_m,
|
||||
max_m), random.randint(min_denominator, max_denominator))
|
||||
m1 = (random.randint(min_m, max_m),
|
||||
random.randint(min_denominator, max_denominator))
|
||||
m2 = (random.randint(min_m, max_m),
|
||||
random.randint(min_denominator, max_denominator))
|
||||
|
||||
b1 = random.randint(min_b, max_b)
|
||||
b2 = random.randint(min_b, max_b)
|
||||
@@ -409,7 +406,8 @@ def invert_matrix(square_matrix_dimension=3,
|
||||
|
||||
for i in range(1, square_matrix_dimension - 1):
|
||||
Mat[i] = [
|
||||
sum(i) for i in zip(Mat[square_matrix_dimension - 1], Mat[i])
|
||||
sum(i)
|
||||
for i in zip(Mat[square_matrix_dimension - 1], Mat[i])
|
||||
]
|
||||
|
||||
isItOk = True
|
||||
@@ -437,7 +435,8 @@ def invert_matrix(square_matrix_dimension=3,
|
||||
square_matrix_dimension * square_matrix_dimension)
|
||||
randomlist = list(set(randomlist) - set(plist))
|
||||
n_list = random.sample(
|
||||
randomlist, square_matrix_dimension * (square_matrix_dimension - 1))
|
||||
randomlist,
|
||||
square_matrix_dimension * (square_matrix_dimension - 1))
|
||||
Mat = list()
|
||||
for i in range(0, square_matrix_dimension):
|
||||
z = list()
|
||||
@@ -504,7 +503,9 @@ def line_equation_from_2_points(max_val=20):
|
||||
y2 = random.randint(-max_val, max_val)
|
||||
m1 = (y2 - y1) // math.gcd(y2 - y1, x2 - x1)
|
||||
m2 = (x2 - x1) // math.gcd(y2 - y1, x2 - x1)
|
||||
c1 = (y1 * (x2 - x1) - (y2 - y1) * x1) // math.gcd(y1 * (x2 - x1) - (y2 - y1) * x1, (x2 - x1))
|
||||
c1 = (y1 * (x2 - x1) -
|
||||
(y2 - y1) * x1) // math.gcd(y1 * (x2 - x1) - (y2 - y1) * x1,
|
||||
(x2 - x1))
|
||||
c2 = (x2 - x1) // math.gcd(y1 * (x2 - x1) - (y2 - y1) * x1, (x2 - x1))
|
||||
c = rf"{'+' if c1 >= 0 else '-'}\frac{{{abs(c1)}}}{{{c2}}}" if c1 != 0 else ""
|
||||
if c2 < 0:
|
||||
@@ -605,9 +606,11 @@ def multiply_complex_numbers(min_real_imaginary_num=-20,
|
||||
| --- | --- |
|
||||
| $(14+18j) * (14+15j) = $ | $(-74+462j)$ |
|
||||
"""
|
||||
num1 = complex(random.randint(min_real_imaginary_num, max_real_imaginary_num),
|
||||
num1 = complex(
|
||||
random.randint(min_real_imaginary_num, max_real_imaginary_num),
|
||||
random.randint(min_real_imaginary_num, max_real_imaginary_num))
|
||||
num2 = complex(random.randint(min_real_imaginary_num, max_real_imaginary_num),
|
||||
num2 = complex(
|
||||
random.randint(min_real_imaginary_num, max_real_imaginary_num),
|
||||
random.randint(min_real_imaginary_num, max_real_imaginary_num))
|
||||
product = num1 * num2
|
||||
|
||||
@@ -652,7 +655,8 @@ def quadratic_equation(max_val=100):
|
||||
a = random.randint(1, max_val)
|
||||
c = random.randint(1, max_val)
|
||||
b = random.randint(
|
||||
round(math.sqrt(4 * a * c)) + 1, round(math.sqrt(4 * max_val * max_val)))
|
||||
round(math.sqrt(4 * a * c)) + 1,
|
||||
round(math.sqrt(4 * max_val * max_val)))
|
||||
D = math.sqrt(b * b - 4 * a * c)
|
||||
res = {round((-b + D) / (2 * a), 2), round((-b - D) / (2 * a), 2)}
|
||||
|
||||
@@ -661,9 +665,7 @@ def quadratic_equation(max_val=100):
|
||||
return problem, solution
|
||||
|
||||
|
||||
def simple_interest(max_principle=10000,
|
||||
max_rate=10,
|
||||
max_time=10):
|
||||
def simple_interest(max_principle=10000, max_rate=10, max_time=10):
|
||||
r"""Simple Interest
|
||||
|
||||
| Ex. Problem | Ex. Solution |
|
||||
@@ -680,9 +682,7 @@ def simple_interest(max_principle=10000,
|
||||
return problem, solution
|
||||
|
||||
|
||||
def system_of_equations(range_x=10,
|
||||
range_y=10,
|
||||
coeff_mult_range=10):
|
||||
def system_of_equations(range_x=10, range_y=10, coeff_mult_range=10):
|
||||
r"""Solve a System of Equations in R^2
|
||||
|
||||
| Ex. Problem | Ex. Solution |
|
||||
|
||||
@@ -75,7 +75,9 @@ def cube_root(min_no=1, max_no=1000):
|
||||
b = random.randint(min_no, max_no)
|
||||
a = b**(1 / 3)
|
||||
|
||||
return (rf"What is the cube root of: $\sqrt[3]{{{b}}}=$ to 2 decimal places?", f"${round(a, 2)}$")
|
||||
return (
|
||||
rf"What is the cube root of: $\sqrt[3]{{{b}}}=$ to 2 decimal places?",
|
||||
f"${round(a, 2)}$")
|
||||
|
||||
|
||||
def divide_fractions(max_val=10):
|
||||
@@ -215,7 +217,6 @@ def greatest_common_divisor(numbers_count=2, max_num=10**3):
|
||||
| --- | --- |
|
||||
| $GCD(488075608, 75348096)=$ | $8$ |
|
||||
"""
|
||||
|
||||
def greatestCommonDivisorOfTwoNumbers(number1, number2):
|
||||
number1 = abs(number1)
|
||||
number2 = abs(number2)
|
||||
@@ -224,8 +225,7 @@ def greatest_common_divisor(numbers_count=2, max_num=10**3):
|
||||
return number1
|
||||
|
||||
numbers_count = max(numbers_count, 2)
|
||||
numbers = [random.randint(0, max_num)
|
||||
for _ in range(numbers_count)]
|
||||
numbers = [random.randint(0, max_num) for _ in range(numbers_count)]
|
||||
|
||||
greatestCommonDivisor = greatestCommonDivisorOfTwoNumbers(
|
||||
numbers[0], numbers[1])
|
||||
|
||||
@@ -24,9 +24,7 @@ def definite_integral(max_coef=100):
|
||||
return problem, f'${solution}$'
|
||||
|
||||
|
||||
def power_rule_differentiation(max_coef=10,
|
||||
max_exp=10,
|
||||
max_terms=5):
|
||||
def power_rule_differentiation(max_coef=10, max_exp=10, max_terms=5):
|
||||
r"""Power Rule Differentiation
|
||||
|
||||
| Ex. Problem | Ex. Solution |
|
||||
@@ -50,9 +48,7 @@ def power_rule_differentiation(max_coef=10,
|
||||
return problem + '$', solution + '$'
|
||||
|
||||
|
||||
def power_rule_integration(max_coef=10,
|
||||
max_exp=10,
|
||||
max_terms=5):
|
||||
def power_rule_integration(max_coef=10, max_exp=10, max_terms=5):
|
||||
r"""Power Rule Integration
|
||||
|
||||
| Ex. Problem | Ex. Solution |
|
||||
|
||||
@@ -67,8 +67,9 @@ def binary_complement_1s(maxDigits=10):
|
||||
| --- | --- |
|
||||
| $1111001 = $ | $0000110$ |
|
||||
"""
|
||||
question = ''.join([str(random.randint(0, 1))
|
||||
for _ in range(random.randint(1, maxDigits))])
|
||||
question = ''.join([
|
||||
str(random.randint(0, 1)) for _ in range(random.randint(1, maxDigits))
|
||||
])
|
||||
answer = ''.join(["0" if digit == "1" else "1" for digit in question])
|
||||
|
||||
problem = f'${question} = $'
|
||||
@@ -82,8 +83,8 @@ def binary_to_decimal(max_dig=10):
|
||||
| --- | --- |
|
||||
| $000110$ | $6$ |
|
||||
"""
|
||||
problem = ''.join([str(random.randint(0, 1))
|
||||
for _ in range(random.randint(1, max_dig))])
|
||||
problem = ''.join(
|
||||
[str(random.randint(0, 1)) for _ in range(random.randint(1, max_dig))])
|
||||
solution = f'${int(problem, 2)}$'
|
||||
return f'${problem}$', solution
|
||||
|
||||
@@ -95,8 +96,8 @@ def binary_to_hex(max_dig=10):
|
||||
| --- | --- |
|
||||
| $010101$ | $0x15$ |
|
||||
"""
|
||||
problem = ''.join([str(random.randint(0, 1))
|
||||
for _ in range(random.randint(1, max_dig))])
|
||||
problem = ''.join(
|
||||
[str(random.randint(0, 1)) for _ in range(random.randint(1, max_dig))])
|
||||
solution = f'${hex(int(problem, 2))}$'
|
||||
return f'${problem}$', solution
|
||||
|
||||
@@ -234,6 +235,7 @@ def nth_tribonacci_number(min_length=1, max_length=80):
|
||||
"""
|
||||
|
||||
tribDict = {0: 0, 1: 0, 2: 1}
|
||||
|
||||
def recTrib(i):
|
||||
if i not in tribDict:
|
||||
tribDict[i] = recTrib(i - 1) + recTrib(i - 2) + recTrib(i - 3)
|
||||
@@ -254,11 +256,14 @@ def tribonacci_series(min_length=1, max_length=80):
|
||||
"""
|
||||
|
||||
tribDict = {0: 0, 1: 0, 2: 1}
|
||||
|
||||
def createTribSeries(i):
|
||||
tribSeries = []
|
||||
for idx in range(i):
|
||||
if idx not in tribDict:
|
||||
tribDict[idx] = tribDict[idx-1] + tribDict[idx-2] + tribDict[idx-3]
|
||||
tribDict[idx] = tribDict[idx -
|
||||
1] + tribDict[idx -
|
||||
2] + tribDict[idx - 3]
|
||||
tribSeries.append(tribDict[idx])
|
||||
return tribSeries
|
||||
|
||||
|
||||
@@ -166,8 +166,10 @@ def basic_trigonometry(angles=[0, 30, 45, 60, 90],
|
||||
1.73: r"\sqrt{3}",
|
||||
}
|
||||
|
||||
solution = result_fraction_map[round(eval(expression), 2)] if round(
|
||||
eval(expression), 2) <= 99999 else r"\infty" # for handling the ∞ condition
|
||||
solution = result_fraction_map[round(
|
||||
eval(expression),
|
||||
2)] if round(eval(expression),
|
||||
2) <= 99999 else r"\infty" # for handling the ∞ condition
|
||||
|
||||
return problem, f'${solution}$'
|
||||
|
||||
@@ -468,14 +470,8 @@ def surface_area_pyramid(unit='m'):
|
||||
| Surface area of pyramid with base length $= 30m$, base width $= 40m$, and height $= 25m$ is | $2400 m^2$ |
|
||||
"""
|
||||
# List of Pythagorean triplets
|
||||
_PYTHAGOREAN = [(3, 4, 5),
|
||||
(6, 8, 10),
|
||||
(9, 12, 15),
|
||||
(12, 16, 20),
|
||||
(15, 20, 25),
|
||||
(5, 12, 13),
|
||||
(10, 24, 26),
|
||||
(7, 24, 25)]
|
||||
_PYTHAGOREAN = [(3, 4, 5), (6, 8, 10), (9, 12, 15), (12, 16, 20),
|
||||
(15, 20, 25), (5, 12, 13), (10, 24, 26), (7, 24, 25)]
|
||||
|
||||
# Generate first triplet
|
||||
height, half_width, triangle_height_1 = random.sample(
|
||||
|
||||
@@ -3,9 +3,7 @@ import math
|
||||
import numpy as np
|
||||
|
||||
|
||||
def arithmetic_progression_sum(max_d=100,
|
||||
max_a=100,
|
||||
max_n=100):
|
||||
def arithmetic_progression_sum(max_d=100, max_a=100, max_n=100):
|
||||
"""Arithmetic Progression Sum
|
||||
|
||||
| Ex. Problem | Ex. Solution |
|
||||
@@ -25,9 +23,7 @@ def arithmetic_progression_sum(max_d=100,
|
||||
return problem, f'${solution}$'
|
||||
|
||||
|
||||
def arithmetic_progression_term(max_d=100,
|
||||
max_a=100,
|
||||
max_n=100):
|
||||
def arithmetic_progression_term(max_d=100, max_a=100, max_n=100):
|
||||
"""Arithmetic Progression Term
|
||||
|
||||
| Ex. Problem | Ex. Solution |
|
||||
@@ -175,15 +171,15 @@ def common_factors(max_val=100):
|
||||
return problem, solution
|
||||
|
||||
|
||||
def complex_to_polar(min_real_imaginary_num=-20,
|
||||
max_real_imaginary_num=20):
|
||||
def complex_to_polar(min_real_imaginary_num=-20, max_real_imaginary_num=20):
|
||||
r"""Complex to polar form
|
||||
|
||||
| Ex. Problem | Ex. Solution |
|
||||
| --- | --- |
|
||||
| $19.42(-19.0\theta + i-4.0\theta)$ | $-2.93$ |
|
||||
"""
|
||||
num = complex(random.randint(min_real_imaginary_num, max_real_imaginary_num),
|
||||
num = complex(
|
||||
random.randint(min_real_imaginary_num, max_real_imaginary_num),
|
||||
random.randint(min_real_imaginary_num, max_real_imaginary_num))
|
||||
a = num.real
|
||||
b = num.imag
|
||||
@@ -224,7 +220,8 @@ def decimal_to_roman_numerals(max_decimal=4000):
|
||||
elif last_value == 4:
|
||||
solution += (roman_dict[div] + roman_dict[div * 5])
|
||||
elif 5 <= last_value <= 8:
|
||||
solution += (roman_dict[div * 5] + (roman_dict[div] * (last_value - 5)))
|
||||
solution += (roman_dict[div * 5] + (roman_dict[div] *
|
||||
(last_value - 5)))
|
||||
elif last_value == 9:
|
||||
solution += (roman_dict[div] + roman_dict[div * 10])
|
||||
x = math.floor(x % div)
|
||||
@@ -436,10 +433,14 @@ def product_of_scientific_notations(min_exp_val=-100, max_exp_val=100):
|
||||
| --- | --- |
|
||||
| Product of scientific notations $5.11 \times 10^{67}$ and $3.64 \times 10^{-59} = $ | $1.86 \times 10^{9}$ |
|
||||
"""
|
||||
a = [round(random.uniform(1, 10), 2),
|
||||
random.randint(min_exp_val, max_exp_val)]
|
||||
b = [round(random.uniform(1, 10), 2),
|
||||
random.randint(min_exp_val, max_exp_val)]
|
||||
a = [
|
||||
round(random.uniform(1, 10), 2),
|
||||
random.randint(min_exp_val, max_exp_val)
|
||||
]
|
||||
b = [
|
||||
round(random.uniform(1, 10), 2),
|
||||
random.randint(min_exp_val, max_exp_val)
|
||||
]
|
||||
c = [a[0] * b[0], a[1] + b[1]]
|
||||
|
||||
if c[0] >= 10:
|
||||
@@ -575,7 +576,6 @@ def surds_comparison(max_value=100, max_root=10):
|
||||
|
||||
|
||||
def velocity_of_object(max_displacement=1000, max_time=100):
|
||||
|
||||
"""Velocity of object
|
||||
|
||||
| Ex. Problem | Ex. Solution |
|
||||
@@ -583,7 +583,6 @@ def velocity_of_object(max_displacement=1000,max_time=100):
|
||||
| An object travels at uniform velocity a distance of $100 m$ in $4$ seconds. What is the velocity of the car? | $25 m/s$ |
|
||||
"""
|
||||
|
||||
|
||||
displacement = random.randint(1, max_displacement)
|
||||
time_taken = random.randint(1, max_time)
|
||||
velocity = "${} m/s$".format(round(displacement / time_taken, 2))
|
||||
|
||||
@@ -12,8 +12,8 @@ def combinations(max_lengthgth=20):
|
||||
a = random.randint(10, max_lengthgth)
|
||||
b = random.randint(0, 9)
|
||||
|
||||
solution = int(math.factorial(
|
||||
a) / (math.factorial(b) * math.factorial(a - b)))
|
||||
solution = int(
|
||||
math.factorial(a) / (math.factorial(b) * math.factorial(a - b)))
|
||||
|
||||
problem = f"Find the number of combinations from ${a}$ objects picked ${b}$ at a time."
|
||||
return problem, f'${solution}$'
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
|
||||
print("You are about to add a new generator to the table in futureGenerators.md")
|
||||
print(
|
||||
"You are about to add a new generator to the table in futureGenerators.md")
|
||||
print("Please fill out the following:")
|
||||
title = input("> Title: ")
|
||||
example_problem = input("> Example Problem: ")
|
||||
@@ -14,4 +15,5 @@ else:
|
||||
|
||||
with open(file, 'a') as f:
|
||||
f.writelines(
|
||||
f'| {title} | {example_problem} | {example_solution} | {further_explanation} |\n')
|
||||
f'| {title} | {example_problem} | {example_solution} | {further_explanation} |\n'
|
||||
)
|
||||
|
||||
@@ -25,8 +25,10 @@ def get_filepaths(subject_name):
|
||||
return file_paths
|
||||
|
||||
|
||||
subjects = ['algebra', 'basic_math', 'calculus',
|
||||
'computer_science', 'geometry', 'misc', 'statistics']
|
||||
subjects = [
|
||||
'algebra', 'basic_math', 'calculus', 'computer_science', 'geometry',
|
||||
'misc', 'statistics'
|
||||
]
|
||||
for subject in subjects:
|
||||
full_file_paths = get_filepaths(subject)
|
||||
full_file_paths.sort()
|
||||
|
||||
Reference in New Issue
Block a user