mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 14:35:23 +01:00
🤖 made makeReadme automated
This commit is contained in:
@@ -71,3 +71,8 @@ from .multiplyComplexNumbersFunc import *
|
||||
from .geomProgrFunc import *
|
||||
from .geometricMeanFunc import *
|
||||
from .harmonicMeanFunc import *
|
||||
from .euclidianNormFunc import *
|
||||
from .angleBtwVectorsFunc import *
|
||||
from .absoluteDifferenceFunc import *
|
||||
from .vectorDotFunc import *
|
||||
from .binary2sComplement import *
|
||||
|
||||
10
mathgenerator/funcs/absoluteDifferenceFunc.py
Normal file
10
mathgenerator/funcs/absoluteDifferenceFunc.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from .__init__ import *
|
||||
|
||||
def absoluteDifferenceFunc (maxA = 100, maxB = 100):
|
||||
a = random.randint(-1*maxA, maxA)
|
||||
b = random.randint(-1*maxB, maxB)
|
||||
absDiff = abs(a-b)
|
||||
|
||||
problem = "Absolute difference between numbers " + str(a) + " and " + str(b) + " = "
|
||||
solution = absDiff
|
||||
return problem, solution
|
||||
16
mathgenerator/funcs/angleBtwVectorsFunc.py
Normal file
16
mathgenerator/funcs/angleBtwVectorsFunc.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from .euclidianNormFunc import euclidianNormFunc
|
||||
import math
|
||||
from .__init__ import *
|
||||
|
||||
|
||||
def angleBtwVectorsFunc(v1: list, v2: list):
|
||||
sum = 0
|
||||
for i in v1:
|
||||
for j in v2:
|
||||
sum += i * j
|
||||
|
||||
mags = euclidianNormFunc(v1) * euclidianNormFunc(v2)
|
||||
problem = f"angle between the vectors {v1} and {v2} is:"
|
||||
solution = math.acos(sum / mags)
|
||||
# would return the answer in radians
|
||||
return problem, solution
|
||||
26
mathgenerator/funcs/binary2sComplement.py
Normal file
26
mathgenerator/funcs/binary2sComplement.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from .__init__ import *
|
||||
|
||||
def binary2sComplementFunc(maxDigits=10):
|
||||
digits = random.randint(1, maxDigits)
|
||||
question = ''.join([str(random.randint(0, 1)) for i in range(digits)]).lstrip('0')
|
||||
|
||||
answer = []
|
||||
for i in question:
|
||||
answer.append(str(int(not bool(int(i)))))
|
||||
|
||||
carry = True
|
||||
j = len(answer) - 1
|
||||
while j >= 0:
|
||||
if answer[j] == '0':
|
||||
answer[j] = '1'
|
||||
carry = False
|
||||
break
|
||||
answer[j] = '0'
|
||||
j -= 1
|
||||
|
||||
if j == 0 and carry == True:
|
||||
answer.insert(0, '1')
|
||||
|
||||
problem = "2's complement of " + question + " ="
|
||||
solution = ''.join(answer).lstrip('0')
|
||||
return problem, solution
|
||||
7
mathgenerator/funcs/euclidianNormFunc.py
Normal file
7
mathgenerator/funcs/euclidianNormFunc.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from .__init__ import *
|
||||
|
||||
|
||||
def euclidianNormFunc(v1: list):
|
||||
problem = f"Euclidian norm or L2 norm of the vector{v1} is:"
|
||||
solution = sqrt(sum([i**2 for i in v1]))
|
||||
return problem, solution
|
||||
11
mathgenerator/funcs/vectorDotFunc.py
Normal file
11
mathgenerator/funcs/vectorDotFunc.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from .__init__ import *
|
||||
|
||||
|
||||
def vectorDotFunc(minVal=-20, maxVal=20):
|
||||
a = [random.randint(minVal, maxVal) for i in range(3)]
|
||||
b = [random.randint(minVal, maxVal) for i in range(3)]
|
||||
c = a[0] * b[0] + a[1] * b[1] + a[2] * b[2]
|
||||
|
||||
problem = str(a) + " . " + str(b) + " = "
|
||||
solution = str(c)
|
||||
return problem, solution
|
||||
Reference in New Issue
Block a user