mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 06:25:23 +01:00
yapf fix
This commit is contained in:
@@ -11,7 +11,8 @@ class Generator:
|
||||
self.generalSol = generalSol
|
||||
self.func = func
|
||||
|
||||
(filename, line_number, function_name, text) = traceback.extract_stack()[-2]
|
||||
(filename, line_number, function_name,
|
||||
text) = traceback.extract_stack()[-2]
|
||||
funcname = filename[filename.rfind('/'):].strip()
|
||||
funcname = funcname[1:-3]
|
||||
# print(funcname)
|
||||
|
||||
@@ -10,7 +10,8 @@ def angleBtwVectorsFunc(maxEltAmt=20):
|
||||
for j in v2:
|
||||
s += i * j
|
||||
|
||||
mags = math.sqrt(sum([i**2 for i in v1])) * math.sqrt(sum([i**2 for i in v2]))
|
||||
mags = math.sqrt(sum([i**2
|
||||
for i in v1])) * math.sqrt(sum([i**2 for i in v2]))
|
||||
problem = f"angle between the vectors {v1} and {v2} is:"
|
||||
solution = ''
|
||||
try:
|
||||
|
||||
@@ -8,11 +8,13 @@ def arithmeticProgressionSumFunc(maxd=100, maxa=100, maxn=100):
|
||||
a3 = a2 + d
|
||||
n = random.randint(4, maxn)
|
||||
apString = str(a1) + ', ' + str(a2) + ', ' + str(a3) + ' ... '
|
||||
problem = 'Find the sum of first ' + str(n) + ' terms of the AP series: ' + apString
|
||||
problem = 'Find the sum of first ' + str(
|
||||
n) + ' terms of the AP series: ' + apString
|
||||
solution = n * ((2 * a1) + ((n - 1) * d)) / 2
|
||||
return problem, solution
|
||||
|
||||
|
||||
arithmetic_progression_sum = Generator("AP Sum Calculation", 83,
|
||||
"Find the sum of first n terms of the AP series: a1, a2, a3 ...",
|
||||
"Sum", arithmeticProgressionSumFunc)
|
||||
arithmetic_progression_sum = Generator(
|
||||
"AP Sum Calculation", 83,
|
||||
"Find the sum of first n terms of the AP series: a1, a2, a3 ...", "Sum",
|
||||
arithmeticProgressionSumFunc)
|
||||
|
||||
@@ -8,11 +8,13 @@ def arithmeticProgressionTermFunc(maxd=100, maxa=100, maxn=100):
|
||||
a3 = a2 + d
|
||||
n = random.randint(4, maxn)
|
||||
apString = str(a1) + ', ' + str(a2) + ', ' + str(a3) + ' ... '
|
||||
problem = 'Find the term number ' + str(n) + ' of the AP series: ' + apString
|
||||
problem = 'Find the term number ' + str(
|
||||
n) + ' of the AP series: ' + apString
|
||||
solution = a1 + ((n - 1) * d)
|
||||
return problem, solution
|
||||
|
||||
|
||||
arithmetic_progression_term = Generator("AP Term Calculation", 82,
|
||||
"Find the term number n of the AP series: a1, a2, a3 ...",
|
||||
"a-n", arithmeticProgressionTermFunc)
|
||||
arithmetic_progression_term = Generator(
|
||||
"AP Term Calculation", 82,
|
||||
"Find the term number n of the AP series: a1, a2, a3 ...", "a-n",
|
||||
arithmeticProgressionTermFunc)
|
||||
|
||||
@@ -5,7 +5,9 @@ alpha = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
|
||||
|
||||
def fromBaseTenTo(n, toBase):
|
||||
assert type(toBase) == int and toBase >= 2 and toBase <= 36, "toBase({}) must be >=2 and <=36"
|
||||
assert type(
|
||||
toBase
|
||||
) == int and toBase >= 2 and toBase <= 36, "toBase({}) must be >=2 and <=36"
|
||||
# trivial cases
|
||||
if toBase == 2:
|
||||
return bin(n)[2:]
|
||||
@@ -16,12 +18,13 @@ def fromBaseTenTo(n, toBase):
|
||||
elif toBase == 16:
|
||||
return hex(n)[2:].upper()
|
||||
res = alpha[n % toBase]
|
||||
n = n//toBase
|
||||
n = n // toBase
|
||||
while n > 0:
|
||||
res = alpha[n % toBase] + res
|
||||
n = n//toBase
|
||||
n = n // toBase
|
||||
return res
|
||||
|
||||
|
||||
# Useful to check answers, but not needed here
|
||||
# def toBaseTen(n,fromBase):
|
||||
# return int(n,fromBase)
|
||||
@@ -29,12 +32,16 @@ def fromBaseTenTo(n, toBase):
|
||||
|
||||
def baseConversionFunc(maxNum=60000, maxBase=16):
|
||||
assert type(
|
||||
maxNum) == int and maxNum >= 100 and maxNum <= 65536, "maxNum({}) must be >=100 and <=65536".format(maxNum)
|
||||
maxNum
|
||||
) == int and maxNum >= 100 and maxNum <= 65536, "maxNum({}) must be >=100 and <=65536".format(
|
||||
maxNum)
|
||||
assert type(
|
||||
maxBase) == int and maxBase >= 2 and maxBase <= 36, "maxBase({}) must be >= 2 and <=36".format(maxBase)
|
||||
maxBase
|
||||
) == int and maxBase >= 2 and maxBase <= 36, "maxBase({}) must be >= 2 and <=36".format(
|
||||
maxBase)
|
||||
|
||||
n = random.randint(40, maxNum)
|
||||
dist = [10]*10+[2]*5+[16]*5+[i for i in range(2, maxBase+1)]
|
||||
dist = [10] * 10 + [2] * 5 + [16] * 5 + [i for i in range(2, maxBase + 1)]
|
||||
# set this way since converting to/from bases 2,10,16 are more common -- can be changed if needed.
|
||||
bases = random.choices(dist, k=2)
|
||||
while bases[0] == bases[1]:
|
||||
@@ -46,5 +53,6 @@ def baseConversionFunc(maxNum=60000, maxBase=16):
|
||||
return problem, ans
|
||||
|
||||
|
||||
base_conversion = Generator("Base Conversion", 94, "Convert 152346 from base 8 to base 10.", "54502",
|
||||
base_conversion = Generator("Base Conversion", 94,
|
||||
"Convert 152346 from base 8 to base 10.", "54502",
|
||||
baseConversionFunc)
|
||||
|
||||
@@ -21,4 +21,5 @@ def BCDtoDecimalFunc(maxNumber=10000):
|
||||
|
||||
|
||||
bcd_to_decimal = Generator("Binary Coded Decimal to Integer", 91,
|
||||
"Integer of Binary Coded Decimal b is ", "n", BCDtoDecimalFunc)
|
||||
"Integer of Binary Coded Decimal b is ", "n",
|
||||
BCDtoDecimalFunc)
|
||||
|
||||
@@ -11,5 +11,5 @@ def binaryToHexFunc(max_dig=10):
|
||||
return problem, solution
|
||||
|
||||
|
||||
binary_to_hex = Generator("Binary to Hexidecimal", 64, "Hexidecimal of a=", "b",
|
||||
binaryToHexFunc)
|
||||
binary_to_hex = Generator("Binary to Hexidecimal", 64, "Hexidecimal of a=",
|
||||
"b", binaryToHexFunc)
|
||||
|
||||
@@ -4,10 +4,12 @@ from .__init__ import *
|
||||
def celsiustofahrenheitFunc(maxTemp=100):
|
||||
celsius = random.randint(-50, maxTemp)
|
||||
fahrenheit = (celsius * (9 / 5)) + 32
|
||||
problem = "Convert " + str(celsius) + " degrees Celsius to degrees Fahrenheit ="
|
||||
problem = "Convert " + str(
|
||||
celsius) + " degrees Celsius to degrees Fahrenheit ="
|
||||
solution = str(fahrenheit)
|
||||
return problem, solution
|
||||
|
||||
|
||||
celsius_to_fahrenheit = Generator("Celsius To Fahrenheit", 81,
|
||||
"(C +(9/5))+32=", "F", celsiustofahrenheitFunc)
|
||||
"(C +(9/5))+32=", "F",
|
||||
celsiustofahrenheitFunc)
|
||||
|
||||
@@ -14,5 +14,5 @@ def complexToPolarFunc(minRealImaginaryNum=-20, maxRealImaginaryNum=20):
|
||||
return problem, solution
|
||||
|
||||
|
||||
complex_to_polar = Generator("Complex To Polar Form", 92,
|
||||
"rexp(itheta) = ", "plr", complexToPolarFunc)
|
||||
complex_to_polar = Generator("Complex To Polar Form", 92, "rexp(itheta) = ",
|
||||
"plr", complexToPolarFunc)
|
||||
|
||||
@@ -14,4 +14,6 @@ def compoundInterestFunc(maxPrinciple=10000, maxRate=10, maxTime=10):
|
||||
|
||||
|
||||
compound_interest = Generator(
|
||||
"Compound Interest", 78, "Compound interest for a principle amount of a dollars, b% rate of interest and for a time period of c years is = ", "d dollars", compoundInterestFunc)
|
||||
"Compound Interest", 78,
|
||||
"Compound interest for a principle amount of a dollars, b% rate of interest and for a time period of c years is = ",
|
||||
"d dollars", compoundInterestFunc)
|
||||
|
||||
@@ -10,5 +10,6 @@ def cubeRootFunc(minNo=1, maxNo=1000):
|
||||
return problem, solution
|
||||
|
||||
|
||||
cube_root = Generator("Cube Root", 47, "Cuberoot of a upto 2 decimal places is",
|
||||
"b", cubeRootFunc)
|
||||
cube_root = Generator("Cube Root", 47,
|
||||
"Cuberoot of a upto 2 decimal places is", "b",
|
||||
cubeRootFunc)
|
||||
|
||||
@@ -5,11 +5,13 @@ def curvedSurfaceAreaCylinderFunc(maxRadius=49, maxHeight=99):
|
||||
r = random.randint(1, maxRadius)
|
||||
h = random.randint(1, maxHeight)
|
||||
problem = f"What is the curved surface area of a cylinder of radius, {r} and height, {h}?"
|
||||
csa = float(2*math.pi*r*h)
|
||||
csa = float(2 * math.pi * r * h)
|
||||
formatted_float = round(csa, 2) # "{:.5f}".format(csa)
|
||||
solution = f"CSA of cylinder = {formatted_float}"
|
||||
return problem, solution
|
||||
|
||||
|
||||
curved_surface_area_cylinder = Generator("Curved surface area of a cylinder", 95,
|
||||
"What is CSA of a cylinder of radius, r and height, h?", "csa of cylinder", curvedSurfaceAreaCylinderFunc)
|
||||
curved_surface_area_cylinder = Generator(
|
||||
"Curved surface area of a cylinder", 95,
|
||||
"What is CSA of a cylinder of radius, r and height, h?", "csa of cylinder",
|
||||
curvedSurfaceAreaCylinderFunc)
|
||||
|
||||
@@ -16,7 +16,7 @@ def dataSummaryFunc(number_values=15, minval=5, maxval=50):
|
||||
var += (random_list[i] - mean)**2
|
||||
|
||||
standardDeviation = var / number_values
|
||||
variance = (var / number_values) ** 0.5
|
||||
variance = (var / number_values)**0.5
|
||||
|
||||
problem = "Find the mean,standard deviation and variance for the data" + \
|
||||
str(random_list)
|
||||
|
||||
@@ -9,4 +9,5 @@ def decimalToOctalFunc(maxDecimal=4096):
|
||||
|
||||
|
||||
decimal_to_octal = Generator("Converts decimal to octal", 84,
|
||||
"What's the octal representation of 98?", "0o142", decimalToOctalFunc)
|
||||
"What's the octal representation of 98?", "0o142",
|
||||
decimalToOctalFunc)
|
||||
|
||||
@@ -4,7 +4,15 @@ from .__init__ import *
|
||||
def decimalToRomanNumeralsFunc(maxDecimal=4000):
|
||||
x = random.randint(0, maxDecimal)
|
||||
problem = "The number " + str(x) + " in Roman Numerals is: "
|
||||
roman_dict = {1: "I", 5: "V", 10: "X", 50: "L", 100: "C", 500: "D", 1000: "M"}
|
||||
roman_dict = {
|
||||
1: "I",
|
||||
5: "V",
|
||||
10: "X",
|
||||
50: "L",
|
||||
100: "C",
|
||||
500: "D",
|
||||
1000: "M"
|
||||
}
|
||||
divisor = 1
|
||||
while x >= divisor:
|
||||
divisor *= 10
|
||||
@@ -17,7 +25,8 @@ def decimalToRomanNumeralsFunc(maxDecimal=4000):
|
||||
elif last_value == 4:
|
||||
solution += (roman_dict[divisor] + roman_dict[divisor * 5])
|
||||
elif 5 <= last_value <= 8:
|
||||
solution += (roman_dict[divisor * 5] + (roman_dict[divisor] * (last_value - 5)))
|
||||
solution += (roman_dict[divisor * 5] + (roman_dict[divisor] *
|
||||
(last_value - 5)))
|
||||
elif last_value == 9:
|
||||
solution += (roman_dict[divisor] + roman_dict[divisor * 10])
|
||||
x = math.floor(x % divisor)
|
||||
@@ -25,5 +34,6 @@ def decimalToRomanNumeralsFunc(maxDecimal=4000):
|
||||
return problem, solution
|
||||
|
||||
|
||||
decimal_to_roman_numerals = Generator("Converts decimal to Roman Numerals",
|
||||
85, "Convert 20 into Roman Numerals", "XX", decimalToRomanNumeralsFunc)
|
||||
decimal_to_roman_numerals = Generator("Converts decimal to Roman Numerals", 85,
|
||||
"Convert 20 into Roman Numerals", "XX",
|
||||
decimalToRomanNumeralsFunc)
|
||||
|
||||
@@ -4,9 +4,8 @@ from scipy.integrate import quad
|
||||
|
||||
|
||||
def definiteIntegralFunc(max_coeff=100):
|
||||
|
||||
def integrand(x, a, b, c):
|
||||
return a * x ** 2 + b * x + c
|
||||
return a * x**2 + b * x + c
|
||||
|
||||
a = random.randint(0, max_coeff)
|
||||
b = random.randint(0, max_coeff)
|
||||
@@ -23,5 +22,7 @@ def definiteIntegralFunc(max_coeff=100):
|
||||
return problem, solution
|
||||
|
||||
|
||||
definite_integral = Generator("Definite Integral of Quadratic Equation", 89,
|
||||
"The definite integral within limits 0 to 1 of quadratic equation ax^2+bx+c is = ", "S", definiteIntegralFunc)
|
||||
definite_integral = Generator(
|
||||
"Definite Integral of Quadratic Equation", 89,
|
||||
"The definite integral within limits 0 to 1 of quadratic equation ax^2+bx+c is = ",
|
||||
"S", definiteIntegralFunc)
|
||||
|
||||
@@ -13,5 +13,5 @@ def degreeToRadFunc(max_deg=360):
|
||||
return problem, solution
|
||||
|
||||
|
||||
degree_to_rad = Generator("Degrees to Radians", 86,
|
||||
"Angle a in radians is = ", "b", degreeToRadFunc)
|
||||
degree_to_rad = Generator("Degrees to Radians", 86, "Angle a in radians is = ",
|
||||
"b", degreeToRadFunc)
|
||||
|
||||
@@ -49,5 +49,6 @@ def differentiationFunc(diff_lvl=2):
|
||||
return problem, solution
|
||||
|
||||
|
||||
differentiation = Generator(
|
||||
"Differentiation", 88, "differentiate w.r.t x : d(f(x))/dx", "g(x)", differentiationFunc)
|
||||
differentiation = Generator("Differentiation", 88,
|
||||
"differentiate w.r.t x : d(f(x))/dx", "g(x)",
|
||||
differentiationFunc)
|
||||
|
||||
@@ -14,6 +14,7 @@ def distanceTwoPointsFunc(maxValXY=20, minValXY=-20):
|
||||
return problem, solution
|
||||
|
||||
|
||||
distance_two_points = Generator("Distance between 2 points", 24,
|
||||
"Find the distance between (x1,y1) and (x2,y2)",
|
||||
"sqrt(distanceSquared)", distanceTwoPointsFunc)
|
||||
distance_two_points = Generator(
|
||||
"Distance between 2 points", 24,
|
||||
"Find the distance between (x1,y1) and (x2,y2)", "sqrt(distanceSquared)",
|
||||
distanceTwoPointsFunc)
|
||||
|
||||
@@ -2,12 +2,15 @@ from .__init__ import *
|
||||
|
||||
|
||||
def euclidianNormFunc(maxEltAmt=20):
|
||||
vec = [random.uniform(0, 1000) for i in range(random.randint(2, maxEltAmt))]
|
||||
vec = [
|
||||
random.uniform(0, 1000) for i in range(random.randint(2, maxEltAmt))
|
||||
]
|
||||
problem = f"Euclidian norm or L2 norm of the vector{vec} is:"
|
||||
solution = math.sqrt(sum([i**2 for i in vec]))
|
||||
return problem, solution
|
||||
|
||||
|
||||
eucldian_norm = Generator("Euclidian norm or L2 norm of a vector", 69,
|
||||
eucldian_norm = Generator(
|
||||
"Euclidian norm or L2 norm of a vector", 69,
|
||||
"Euclidian Norm of a vector V:[v1, v2, ......., vn]",
|
||||
"sqrt(v1^2 + v2^2 ........ +vn^2)", euclidianNormFunc)
|
||||
|
||||
@@ -27,6 +27,7 @@ def geometricMeanFunc(maxValue=100, maxNum=4):
|
||||
return problem, solution
|
||||
|
||||
|
||||
geometric_mean = Generator("Geometric Mean of N Numbers", 67,
|
||||
geometric_mean = Generator(
|
||||
"Geometric Mean of N Numbers", 67,
|
||||
"Geometric mean of n numbers A1 , A2 , ... , An = ",
|
||||
"(A1*A2*...An)^(1/n) = ans", geometricMeanFunc)
|
||||
|
||||
@@ -78,5 +78,6 @@ def matrixInversion(SquareMatrixDimension=3,
|
||||
return problem, solution
|
||||
|
||||
|
||||
invert_matrix = Generator("Inverse of a Matrix", 74, "Inverse of a matrix A is",
|
||||
"A^(-1)", matrixInversion)
|
||||
invert_matrix = Generator("Inverse of a Matrix", 74,
|
||||
"Inverse of a matrix A is", "A^(-1)",
|
||||
matrixInversion)
|
||||
|
||||
@@ -18,5 +18,5 @@ def isprime(max_a=100):
|
||||
return (problem, solution)
|
||||
|
||||
|
||||
is_prime = Generator('isprime', 90, 'a any positive integer',
|
||||
'True/False', isprime)
|
||||
is_prime = Generator('isprime', 90, 'a any positive integer', 'True/False',
|
||||
isprime)
|
||||
|
||||
@@ -13,5 +13,6 @@ def MidPointOfTwoPointFunc(maxValue=20):
|
||||
|
||||
|
||||
midPoint_of_two_points = Generator("Midpoint of the two point", 20,
|
||||
"((X1,Y1),(X2,Y2))=", "((X1+X2)/2,(Y1+Y2)/2)",
|
||||
"((X1,Y1),(X2,Y2))=",
|
||||
"((X1+X2)/2,(Y1+Y2)/2)",
|
||||
MidPointOfTwoPointFunc)
|
||||
|
||||
@@ -5,7 +5,8 @@ def nthFibonacciNumberFunc(maxN=100):
|
||||
golden_ratio = (1 + math.sqrt(5)) / 2
|
||||
n = random.randint(1, maxN)
|
||||
problem = f"What is the {n}th Fibonacci number?"
|
||||
ans = round((math.pow(golden_ratio, n) - math.pow(-golden_ratio, -n)) / (math.sqrt(5)))
|
||||
ans = round((math.pow(golden_ratio, n) - math.pow(-golden_ratio, -n)) /
|
||||
(math.sqrt(5)))
|
||||
solution = f"{ans}"
|
||||
return problem, solution
|
||||
|
||||
|
||||
@@ -18,6 +18,6 @@ def powerRuleDifferentiationFunc(maxCoef=10, maxExp=10, maxTerms=5):
|
||||
return problem, solution
|
||||
|
||||
|
||||
power_rule_differentiation = Generator("Power Rule Differentiation", 7, "nx^m=",
|
||||
"(n*m)x^(m-1)",
|
||||
power_rule_differentiation = Generator("Power Rule Differentiation", 7,
|
||||
"nx^m=", "(n*m)x^(m-1)",
|
||||
powerRuleDifferentiationFunc)
|
||||
|
||||
@@ -14,5 +14,5 @@ def radianToDegFunc(max_rad=3):
|
||||
return problem, solution
|
||||
|
||||
|
||||
radian_to_deg = Generator("Radians to Degrees", 87,
|
||||
"Angle a in degrees is = ", "b", radianToDegFunc)
|
||||
radian_to_deg = Generator("Radians to Degrees", 87, "Angle a in degrees is = ",
|
||||
"b", radianToDegFunc)
|
||||
|
||||
@@ -12,5 +12,5 @@ def sectorAreaFunc(maxRadius=49, maxAngle=359):
|
||||
|
||||
|
||||
sector_area = Generator("Area of a Sector", 75,
|
||||
"Area of a sector with radius, r and angle, a ", "Area",
|
||||
sectorAreaFunc)
|
||||
"Area of a sector with radius, r and angle, a ",
|
||||
"Area", sectorAreaFunc)
|
||||
|
||||
@@ -14,11 +14,14 @@ def set_operation(minval=3, maxval=7, n_a=4, n_b=5):
|
||||
b = set(b)
|
||||
problem = "Given the two sets a=" + \
|
||||
str(a) + " ,b=" + str(b) + ".Find the Union,intersection,a-b,b-a and symmetric difference"
|
||||
solution = "Union is " + str(a.union(b)) + ",Intersection is " + str(a.intersection(b)) + ", a-b is " + str(
|
||||
a.difference(b)) + ",b-a is " + str(b.difference(a)) + ", Symmetric difference is " + str(a.symmetric_difference(b))
|
||||
solution = "Union is " + str(a.union(b)) + ",Intersection is " + str(
|
||||
a.intersection(b)) + ", a-b is " + str(
|
||||
a.difference(b)) + ",b-a is " + str(
|
||||
b.difference(a)) + ", Symmetric difference is " + str(
|
||||
a.symmetric_difference(b))
|
||||
return problem, solution
|
||||
|
||||
|
||||
set_operation = Generator("Union,Intersection,Difference of Two Sets", 93,
|
||||
"Union,intersection,difference",
|
||||
"aUb,a^b,a-b,b-a,", set_operation)
|
||||
"Union,intersection,difference", "aUb,a^b,a-b,b-a,",
|
||||
set_operation)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from .funcs import *
|
||||
from .__init__ import getGenList
|
||||
|
||||
|
||||
genList = getGenList()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user