mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 14:35:23 +01:00
Move files to subject folders
This commit is contained in:
0
mathgenerator/funcs/computer_science/__init__.py
Normal file
0
mathgenerator/funcs/computer_science/__init__.py
Normal file
25
mathgenerator/funcs/computer_science/bcd_to_decimal.py
Normal file
25
mathgenerator/funcs/computer_science/bcd_to_decimal.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from .__init__ import *
|
||||
|
||||
|
||||
def BCDtoDecimalFunc(maxNumber=10000):
|
||||
n = random.randint(1000, maxNumber)
|
||||
binstring = ''
|
||||
while True:
|
||||
q, r = divmod(n, 10)
|
||||
nibble = bin(r).replace('0b', "")
|
||||
while len(nibble) < 4:
|
||||
nibble = '0' + nibble
|
||||
binstring = nibble + binstring
|
||||
if q == 0:
|
||||
break
|
||||
else:
|
||||
n = q
|
||||
|
||||
problem = "Integer of Binary Coded Decimal " + str(n) + " is = "
|
||||
solution = int(binstring, 2)
|
||||
return problem, solution
|
||||
|
||||
|
||||
bcd_to_decimal = Generator("Binary Coded Decimal to Integer", 91,
|
||||
"Integer of Binary Coded Decimal b is ", "n",
|
||||
BCDtoDecimalFunc)
|
||||
33
mathgenerator/funcs/computer_science/binary_2s_complement.py
Normal file
33
mathgenerator/funcs/computer_science/binary_2s_complement.py
Normal file
@@ -0,0 +1,33 @@
|
||||
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 is True:
|
||||
answer.insert(0, '1')
|
||||
|
||||
problem = "2's complement of " + question + " ="
|
||||
solution = ''.join(answer).lstrip('0')
|
||||
return problem, solution
|
||||
|
||||
|
||||
binary_2s_complement = Generator("Binary 2's Complement", 73,
|
||||
"2's complement of 11010110 =", "101010",
|
||||
binary2sComplementFunc)
|
||||
19
mathgenerator/funcs/computer_science/binary_complement_1s.py
Normal file
19
mathgenerator/funcs/computer_science/binary_complement_1s.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from .__init__ import *
|
||||
|
||||
|
||||
def binaryComplement1sFunc(maxDigits=10):
|
||||
question = ''
|
||||
answer = ''
|
||||
|
||||
for i in range(random.randint(1, maxDigits)):
|
||||
temp = str(random.randint(0, 1))
|
||||
question += temp
|
||||
answer += "0" if temp == "1" else "1"
|
||||
|
||||
problem = question + "="
|
||||
solution = answer
|
||||
return problem, solution
|
||||
|
||||
|
||||
binary_complement_1s = Generator("Binary Complement 1s", 4, "1010=", "0101",
|
||||
binaryComplement1sFunc)
|
||||
16
mathgenerator/funcs/computer_science/binary_to_decimal.py
Normal file
16
mathgenerator/funcs/computer_science/binary_to_decimal.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from .__init__ import *
|
||||
|
||||
|
||||
def binaryToDecimalFunc(max_dig=10):
|
||||
problem = ''
|
||||
|
||||
for i in range(random.randint(1, max_dig)):
|
||||
temp = str(random.randint(0, 1))
|
||||
problem += temp
|
||||
|
||||
solution = int(problem, 2)
|
||||
return problem, solution
|
||||
|
||||
|
||||
binary_to_decimal = Generator("Binary to Decimal", 15, "Decimal of a=", "b",
|
||||
binaryToDecimalFunc)
|
||||
15
mathgenerator/funcs/computer_science/binary_to_hex.py
Normal file
15
mathgenerator/funcs/computer_science/binary_to_hex.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from .__init__ import *
|
||||
|
||||
|
||||
def binaryToHexFunc(max_dig=10):
|
||||
problem = ''
|
||||
for i in range(random.randint(1, max_dig)):
|
||||
temp = str(random.randint(0, 1))
|
||||
problem += temp
|
||||
|
||||
solution = hex(int(problem, 2))
|
||||
return problem, solution
|
||||
|
||||
|
||||
binary_to_hex = Generator("Binary to Hexidecimal", 64, "Hexidecimal of a=",
|
||||
"b", binaryToHexFunc)
|
||||
21
mathgenerator/funcs/computer_science/decimal_to_bcd.py
Normal file
21
mathgenerator/funcs/computer_science/decimal_to_bcd.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from .__init__ import *
|
||||
|
||||
|
||||
def DecimalToBCDFunc(maxNumber=10000):
|
||||
n = random.randint(1000, maxNumber)
|
||||
x = n
|
||||
# binstring = ''
|
||||
bcdstring = ''
|
||||
while x > 0:
|
||||
nibble = x % 16
|
||||
bcdstring = str(nibble) + bcdstring
|
||||
x >>= 4
|
||||
|
||||
problem = "BCD of Decimal Number " + str(n) + " is = "
|
||||
solution = int(bcdstring)
|
||||
return problem, solution
|
||||
|
||||
|
||||
decimal_to_bcd = Generator("Decimal to Binary Coded Decimal", 103,
|
||||
"Binary Coded Decimal of Decimal n is ", "b",
|
||||
DecimalToBCDFunc)
|
||||
15
mathgenerator/funcs/computer_science/decimal_to_binary.py
Normal file
15
mathgenerator/funcs/computer_science/decimal_to_binary.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from .__init__ import *
|
||||
|
||||
|
||||
def DecimalToBinaryFunc(max_dec=99):
|
||||
a = random.randint(1, max_dec)
|
||||
b = bin(a).replace("0b", "")
|
||||
|
||||
problem = "Binary of " + str(a) + "="
|
||||
solution = str(b)
|
||||
|
||||
return problem, solution
|
||||
|
||||
|
||||
decimal_to_binary = Generator("Decimal to Binary", 14, "Binary of a=", "b",
|
||||
DecimalToBinaryFunc)
|
||||
14
mathgenerator/funcs/computer_science/decimal_to_hexadeci.py
Normal file
14
mathgenerator/funcs/computer_science/decimal_to_hexadeci.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from .__init__ import *
|
||||
|
||||
|
||||
def deciToHexaFunc(max_dec=1000):
|
||||
a = random.randint(0, max_dec)
|
||||
b = hex(a)
|
||||
problem = "Binary of " + str(a) + "="
|
||||
solution = str(b)
|
||||
|
||||
return problem, solution
|
||||
|
||||
|
||||
decimal_to_hexadeci = Generator("Decimal to Hexadecimal", 79, "Binary of a=",
|
||||
"b", deciToHexaFunc)
|
||||
13
mathgenerator/funcs/computer_science/decimal_to_octal.py
Normal file
13
mathgenerator/funcs/computer_science/decimal_to_octal.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from .__init__ import *
|
||||
|
||||
|
||||
def decimalToOctalFunc(maxDecimal=4096):
|
||||
x = random.randint(0, maxDecimal)
|
||||
problem = "The decimal number " + str(x) + " in Octal is: "
|
||||
solution = oct(x)
|
||||
return problem, solution
|
||||
|
||||
|
||||
decimal_to_octal = Generator("Converts decimal to octal", 84,
|
||||
"What's the octal representation of 98?", "0o142",
|
||||
decimalToOctalFunc)
|
||||
26
mathgenerator/funcs/computer_science/fibonacci_series.py
Normal file
26
mathgenerator/funcs/computer_science/fibonacci_series.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from .__init__ import *
|
||||
|
||||
|
||||
def fibonacciSeriesFunc(minNo=1):
|
||||
n = random.randint(minNo, 20)
|
||||
|
||||
def createFibList(n):
|
||||
list = []
|
||||
for i in range(n):
|
||||
if i < 2:
|
||||
list.append(i)
|
||||
else:
|
||||
val = list[i - 1] + list[i - 2]
|
||||
list.append(val)
|
||||
return list
|
||||
|
||||
fibList = createFibList(n)
|
||||
|
||||
problem = "The Fibonacci Series of the first " + str(n) + " numbers is ?"
|
||||
solution = fibList
|
||||
return problem, solution
|
||||
|
||||
|
||||
fibonacci_series = Generator(
|
||||
"Fibonacci Series", 56, "fibonacci series of first a numbers",
|
||||
"prints the fibonacci series starting from 0 to a", fibonacciSeriesFunc)
|
||||
14
mathgenerator/funcs/computer_science/modulo_division.py
Normal file
14
mathgenerator/funcs/computer_science/modulo_division.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from .__init__ import *
|
||||
|
||||
|
||||
def moduloFunc(maxRes=99, maxModulo=99):
|
||||
a = random.randint(0, maxModulo)
|
||||
b = random.randint(0, min(maxRes, maxModulo))
|
||||
c = a % b if b != 0 else 0
|
||||
|
||||
problem = str(a) + "%" + str(b) + "="
|
||||
solution = str(c)
|
||||
return problem, solution
|
||||
|
||||
|
||||
modulo_division = Generator("Modulo Division", 5, "a%b=", "c", moduloFunc)
|
||||
15
mathgenerator/funcs/computer_science/nth_fibonacci_number.py
Normal file
15
mathgenerator/funcs/computer_science/nth_fibonacci_number.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from .__init__ import *
|
||||
|
||||
|
||||
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)))
|
||||
solution = f"{ans}"
|
||||
return problem, solution
|
||||
|
||||
|
||||
nth_fibonacci_number = Generator("nth Fibonacci number", 62,
|
||||
"What is the nth Fibonacci number", "Fn",
|
||||
nthFibonacciNumberFunc)
|
||||
Reference in New Issue
Block a user