Merge branch 'master' into feature/condProb

This commit is contained in:
Luke Weiler
2020-10-23 13:54:48 -04:00
committed by GitHub
8 changed files with 229 additions and 103 deletions

View File

@@ -105,4 +105,9 @@ from .power_of_powers import *
from .quotient_of_power_same_base import *
from .quotient_of_power_same_power import *
from .complex_quadratic import *
from .conditionalProbability import *
from .is_leap_year import *
from .minutes_to_hours import *
from .decimal_to_bcd import *
from .circumference import *
from .combine_like_terms import *
from .conditional_probability import *

View File

@@ -0,0 +1,13 @@
from .__init__ import *
def circumferenceCircle(maxRadius=100):
r = random.randint(0, maxRadius)
pi = 22/7
circumference = 2*pi*r
problem = f"Circumference of circle with radius {r}"
solution = circumference
return problem, solution
circumference = Generator("Circumference", 104, "2*pi*r=", "circumference", circumferenceCircle)

View File

@@ -0,0 +1,45 @@
from .__init__ import *
def likeTermCombineFunc(maxCoef=10, maxExp=20, maxTerms=10):
numTerms = random.randint(1, maxTerms)
problem = ""
solution = ""
for i in range(numTerms):
if i > 0:
problem += " + "
solution += " + "
coefficient = random.randint(1, maxCoef)
exponent = random.randint(1, max(numTerms - 1, 2))
problem += str(coefficient) + "x^" + str(exponent)
solution = combineTerms(problem)
return problem, solution
def combineTerms(string):
each_terms = string.split("+")
dict_power_wise_terms = {}
for i in range(11):
dict_power_wise_terms[i] = []
for term in each_terms:
term = term.split("^")
appendee = term[0].split("x")[0]
if len(term) == 1:
dict_power_wise_terms[1].append(int(appendee))
else:
dict_power_wise_terms[int(term[1])].append(int(appendee))
final_string = ''
for i in range(11):
if len(dict_power_wise_terms[i]) != 0:
total = sum(dict_power_wise_terms[i])
final_string += str(total) + "x^" + str(i) + " + "
final_string = '+'.join(final_string.split("+")[:-1])
return final_string
combine_like_terms = Generator("Combine Like terms", 105, "nx^m+lx^k+bx^m",
"(n+b)x^m+lx^k", likeTermCombineFunc)

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,25 @@
from .__init__ import *
def IsLeapYear(minNumber=1900, maxNumber=2099):
year = random.randint(minNumber, maxNumber)
problem = "Year " + str(year) + " "
solution = ""
if (year % 4) == 0:
if (year % 100) == 0:
if (year % 400) == 0:
solution = "is a leap year"
else:
solution = "is not a leap year"
else:
solution = "is a leap year"
else:
solution = "is not a leap year"
return problem, solution
is_leap_year = Generator("Leap Year or Not", 101,
"Year y ", "is/not a leap year",
IsLeapYear)
# for readme ## | 102 | Leap Year or Not | Year 1964 | is a leap year | is_leap_year |

View File

@@ -0,0 +1,14 @@
from .__init__ import *
def minutesToHoursFunc(maxMinutes=999):
minutes = random.randint(1, maxMinutes)
hours1 = int(minutes / 60)
hours2 = minutes % 60
problem = f"Convert {minutes} minutes to Hours & Minutes"
solution = f"{hours1} hours and {hours2} minutes"
return problem, solution
minutes_to_hours = Generator("Minute to Hour conversion", 102,
"Convert minutes to Hours & Minutes", "hours:minutes", minutesToHoursFunc)