Move files to subject folders

This commit is contained in:
lukew3
2020-11-20 20:17:28 -05:00
parent ef8b266845
commit 5367e5a151
120 changed files with 0 additions and 0 deletions

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)