Beispiel #1
0
def unionThreeEventsProblem():
    try:
        p = random.randint(200, 250)
        n1 = random.randint(50, 75)
        n2 = random.randint(50, 75)
        n3 = random.randint(50, 75)
        m12 = random.randint(15, 25)
        m13 = random.randint(15, 25)
        m23 = random.randint(15, 25)
        m123 = random.randint(5, 10)
        sol1 = p - (n1 + n2 + n3 - m12 - m13 - m23 + m123)
        sol2 = n1 - m12 - m13 + m123
        solution = r"a) " + str(sol1) + r", b) " + str(sol2) + r""
        question = r"A class have " + str(
            p
        ) + r" students. After scholar year has finished the teacher provide the next report:  " + str(
            n1
        ) + r" students pass maths, " + str(
            n2
        ) + r" students pass english, " + str(
            n3
        ) + r" students pass science, " + str(
            m12
        ) + r" students pass both math and english,\\ " + str(
            m13
        ) + r" students pass both math and science, " + str(
            m23
        ) + r" students pass both english and science,  " + str(
            m123
        ) + r" students pass three courses,\\ a) how many students fail all the three courses?, b) how many students fail both english and science but pass math?: "
        alternatives = coursesFunctionsBll.multiAritmeticOptions([sol1, sol2],
                                                                 5)
        tempAlternatives = []
        for ta in range(5):
            tempAlternatives.append(r"a) " + str(alternatives[ta][0]) +
                                    r", b) " + str(alternatives[ta][1]) + r"")
        options = json.loads(
            json.dumps({
                'a': tempAlternatives[0],
                'b': tempAlternatives[1],
                'c': tempAlternatives[2],
                'd': tempAlternatives[3],
                'e': tempAlternatives[4]
            }))
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
Beispiel #2
0
def vennDiagramProblem():
    try:
        p = random.randint(100, 150)
        n1 = random.randint(25, 50)
        n2 = random.randint(25, 50)
        n3 = random.randint(25, 50)
        n4 = random.randint(25, 50)
        m1 = random.randint(10, 20)
        m2 = random.randint(10, 20)
        sol1 = n1 + n2 - m1
        sol2 = p - (n3 + n4 - m2)
        solution = r"a) " + str(sol1) + r", b) " + str(sol2) + r""
        question = r"A class have " + str(
            p
        ) + r" students. After scholar year has finished the teacher provide the next report: " + str(
            n1
        ) + r" students pass maths, " + str(
            n2
        ) + r" students pass english, " + str(
            n3
        ) + r" students pass science, " + str(
            n4
        ) + r" students pass spanish,\\ " + str(
            m1
        ) + r" students pass both math and english, " + str(
            m2
        ) + r" students pass both science and spanish. \\a) how many students pass either math or english?, b) how many students fail both science and spanish?: "
        alternatives = coursesFunctionsBll.multiAritmeticOptions([sol1, sol2],
                                                                 5)
        tempAlternatives = []
        for ta in range(5):
            tempAlternatives.append(r"a) " + str(alternatives[ta][0]) +
                                    r", b) " + str(alternatives[ta][1]) + r"")
        options = json.loads(
            json.dumps({
                'a': tempAlternatives[0],
                'b': tempAlternatives[1],
                'c': tempAlternatives[2],
                'd': tempAlternatives[3],
                'e': tempAlternatives[4]
            }))
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
Beispiel #3
0
def permutationsProblem():
    try:
        names = [
            "oscar", "andres", "juan", "felipe", "carlos", "alberto", "juan",
            "pablo", "jose", "luis", "sergio", "camilo", "leonardo", "ramiro",
            "fran", "fernando", "gerardo", "patricio", "paolo", "waldo",
            "wilmer", "nicolas"
        ]
        randomName = names[random.randint(0, 21)] + " " + names[random.randint(
            0, 21)]
        listName = list(randomName)
        sol1 = math.factorial(len(listName))
        groups = coursesFunctionsBll.countBy(listName)
        for i in range(len(groups)):
            sol1 = sol1 / math.factorial(groups[i][1])
        setName = set(listName)
        sol2 = math.factorial(len(setName))
        solution = r"a) " + str(sol1) + r", b) " + str(sol2)
        question = r"A math student whose name is " + str(
            randomName
        ) + r" would like to know a) how many different rearrangements can be done with his name, b) taking just one time each different character in his name, how many different rearragements can be? PS: consider white space as another character."
        alternatives = coursesFunctionsBll.multiAritmeticOptions([sol1, sol2],
                                                                 5)
        tempAlternatives = []
        for ta in range(5):
            tempAlternatives.append(r"a) " + str(alternatives[ta][0]) +
                                    r", b) " + str(alternatives[ta][1]))
        options = json.loads(
            json.dumps({
                'a': tempAlternatives[0],
                'b': tempAlternatives[1],
                'c': tempAlternatives[2],
                'd': tempAlternatives[3],
                'e': tempAlternatives[4]
            }))
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
Beispiel #4
0
def conditionalProbabilityProblem():
    try:
        f = random.randint(41, 60)
        ft = random.randint(21, 40)
        i = random.randint(41, 60)
        fi = random.randint(21, 40)
        sol1 = round(ft * 100 / f, 4)
        sol2 = round(fi * 100 / (f + i - fi), 4)
        solution = r"a) " + str(sol1) + r"\%, b) " + str(sol2) + r"\%"
        question = r"A government made a poll to find the citizens preferences about social networks, they get the next conclusions, " + str(
            f
        ) + r"\% of citizens use facebook,\\ " + str(
            ft
        ) + r"\% of citizens use both twitter and facebook, " + str(
            i
        ) + r"\% of citizens use instagram, " + str(
            fi
        ) + r"\% of citizens use both instagram and facebook. Using this information solve the next questions\\ a) which is the probability of citizen use twitter if we know he use facebook?, b) which is the probability a citizen use both facebook and instagram if we know he use one of those two social networks?:"
        alternatives = coursesFunctionsBll.multiAritmeticOptions([sol1, sol2],
                                                                 5)
        tempAlternatives = []
        for ta in range(5):
            tempAlternatives.append(r"a) " + str(alternatives[ta][0]) +
                                    r"\%, b) " + str(alternatives[ta][1]) +
                                    r"\%")
        options = json.loads(
            json.dumps({
                'a': tempAlternatives[0],
                'b': tempAlternatives[1],
                'c': tempAlternatives[2],
                'd': tempAlternatives[3],
                'e': tempAlternatives[4]
            }))
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
Beispiel #5
0
def mutuallyExclusiveProblem():
    try:
        p = random.randint(325, 350)
        na = random.randint(125, 150)
        anb = random.randint(75, 100)
        abnc = random.randint(25, 50)
        sol1 = na + anb + abnc
        a = p - na
        sol2 = a - anb
        solution = r"a) " + str(sol1) + r", b) " + str(sol2) + r""
        question = r"Microsoft choose a sample of " + str(
            p
        ) + " employees in order to understand their main habits. They found the next information, " + str(
            na
        ) + r" employees of the group don't read books,\\ " + str(
            anb
        ) + r" employees read books but don't play an instrument, " + str(
            abnc
        ) + r" employees read books and play an instrument but don't exercise.Using the provide information answer the next questions, \\a) how many employees don't read or don't play an instrument or don't exercise?, b) how many employees both read books and play an instrument?: "
        alternatives = coursesFunctionsBll.multiAritmeticOptions([sol1, sol2],
                                                                 5)
        tempAlternatives = []
        for ta in range(5):
            tempAlternatives.append(r"a) " + str(alternatives[ta][0]) +
                                    r", b) " + str(alternatives[ta][1]) + r"")
        options = json.loads(
            json.dumps({
                'a': tempAlternatives[0],
                'b': tempAlternatives[1],
                'c': tempAlternatives[2],
                'd': tempAlternatives[3],
                'e': tempAlternatives[4]
            }))
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
Beispiel #6
0
def conditionalProbabilityProblem3():
    try:
        a = random.randint(41, 60) / 100
        b = random.randint(41, 60) / 100
        ab = random.randint(21, 40) / 100
        sol1 = round((a - ab) * 100, 4)
        pba = ab / a
        sol2 = round((1 - pba) * 100, 4)
        solution = r"a) " + str(sol1) + r"\%, b) " + str(sol2) + r"\%"
        question = r"if A,B are events in S, where P(A)=" + str(
            round(a * 100)
        ) + r"\%,P(B)=" + str(round(b * 100)) + r"\%,P(AB)=" + str(
            round(ab * 100)
        ) + r"\%, then find the value of a) P(A \cap B^{c}) b) P(B^{c}|A): "
        alternatives = coursesFunctionsBll.multiAritmeticOptions([sol1, sol2],
                                                                 5)
        tempAlternatives = []
        for ta in range(5):
            tempAlternatives.append(r"a) " + str(alternatives[ta][0]) +
                                    r"\%, b) " + str(alternatives[ta][1]) +
                                    r"\%")
        options = json.loads(
            json.dumps({
                'a': tempAlternatives[0],
                'b': tempAlternatives[1],
                'c': tempAlternatives[2],
                'd': tempAlternatives[3],
                'e': tempAlternatives[4]
            }))
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
Beispiel #7
0
def cpRepetitionProblem():
    try:
        f = random.randint(7, 11)
        c = random.randint(2, 6)
        p = random.randint(2, 6)
        combi = math.factorial(f - 1 + c) / (math.factorial(f - 1) *
                                             math.factorial(c))
        permu = f**p
        solution = r"a) " + str(combi) + r" b)" + str(permu)
        question = r"from the first " + str(
            f
        ) + r" characters of alphabet, if you can repeat each character as many times as you want, a) how many ways of choose " + str(
            c) + r" characters can be done b) how many words of " + str(
                p) + r" characters can be done: "
        alternatives = coursesFunctionsBll.multiAritmeticOptions(
            [combi, permu], 5)
        tempAlternatives = []
        for ta in range(5):
            tempAlternatives.append(r"a) " + str(alternatives[ta][0]) +
                                    r" b)" + str(alternatives[ta][1]))
        options = json.loads(
            json.dumps({
                'a': tempAlternatives[0],
                'b': tempAlternatives[1],
                'c': tempAlternatives[2],
                'd': tempAlternatives[3],
                'e': tempAlternatives[4]
            }))
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
Beispiel #8
0
def multiplicationCombinationProblem():
    try:
        b = random.randint(6, 10)
        g = random.randint(6, 10)
        s = random.randint(2, 10)
        m = b * g
        p = (math.factorial(b + g)) / (math.factorial(s) *
                                       math.factorial((b + g) - s))

        solution = r"a) " + str(m) + r", b) " + str(p)
        question = r"For a class with " + str(b) + r" boys and " + str(
            g
        ) + r" girls, a) if the teacher has to choose one boy and one girl, how many possible outcomes can be? b) from the whole class the teacher must select " + str(
            s) + r" students, how many different group of students can appear?"
        alternatives = coursesFunctionsBll.multiAritmeticOptions([m, p], 5)
        tempAlternatives = []
        for ta in range(5):
            tempAlternatives.append(r"a) " + str(alternatives[ta][0]) +
                                    r", b) " + str(alternatives[ta][1]))
        options = json.loads(
            json.dumps({
                'a': tempAlternatives[0],
                'b': tempAlternatives[1],
                'c': tempAlternatives[2],
                'd': tempAlternatives[3],
                'e': tempAlternatives[4]
            }))
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
Beispiel #9
0
def combinationPermutationProblem():
    try:
        f = random.randint(11, 14)
        c = random.randint(2, 9)
        p = random.randint(2, 9)
        combi = math.factorial(f) / (math.factorial(f - c) * math.factorial(c))
        permu = math.factorial(f) / math.factorial(f - p)
        solution = r"a) " + str(combi) + r" b)" + str(permu)
        question = r"In a family there are " + str(
            f) + r" siblings, a) how many groups of " + str(
                c) + r" siblings can be formed b) how many groups of " + str(
                    p) + r" if order is important: "
        alternatives = coursesFunctionsBll.multiAritmeticOptions(
            [combi, permu], 5)
        tempAlternatives = []
        for ta in range(5):
            tempAlternatives.append(r"a) " + str(alternatives[ta][0]) +
                                    r" b)" + str(alternatives[ta][1]))
        options = json.loads(
            json.dumps({
                'a': tempAlternatives[0],
                'b': tempAlternatives[1],
                'c': tempAlternatives[2],
                'd': tempAlternatives[3],
                'e': tempAlternatives[4]
            }))
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
Beispiel #10
0
def profitProblem():
    try:
        r = random.randint(2, 100)
        a0 = random.randint(2,100)
        b = random.randint(2,100)*(-1)
        c = random.randint(2,100)*(-1)
        
        a=1/a0
        a1= a*2*(-1)
        b1= b*(-1)
        c1 = r-c

        tempx1=round((-b1+math.sqrt((b1**2)-(4*a1*c1)))/(2*a1),4)
        tempx2=round((-b1-math.sqrt((b1**2)-(4*a1*c1)))/(2*a1),4)
        x1 = -1000 if tempx1<=0 else math.log(tempx1)
        x2 = -1000 if tempx2<=0 else math.log(tempx2)
        xMax=  x1 if x1>x2 else x2
        x01 = math.floor(xMax)
        x02 = math.ceil(xMax)

        y1 = round((-a*(math.e**(2*x01)))+(-b*(math.e**(x01)))+((r-c)*x01),4)
        y2 = round((-a*(math.e**(2*x02)))+(-b*(math.e**(x02)))+((r-c)*x02),4)

        xSol=  x01 if y1>y2 else x02
        ySol = y1 if y1>y2 else y2
        solution = r"Units="+str(xSol)+r", profit="+str(ySol)+r"."
        question=r"A shoes fabric produce x units of shoes every day, its total revenue is "+str(r)+r"x (where x es the number of shoes they produce) and the total cost of production is \frac{1}{"+str(a0)+r"}*e^{2x} "+str(b)+r"*e^{x} "+str(c)+r"x. Find the max profit and the units to maximize the profit: "
        alternatives = coursesFunctionsBll.multiAritmeticOptions([xSol, ySol],5)
        tempAlternatives =[]
        for m in range(5):
            tempAlternatives.append(r"Units="+str(alternatives[m][0])+r", profit="+str(alternatives[m][1])+r".")
        options =json.loads(json.dumps({'a':tempAlternatives[0], 'b':tempAlternatives[1], 'c': tempAlternatives[2], 'd': tempAlternatives[3], 'e': tempAlternatives[4]}))
        jsonResponse = json.dumps({"question":coursesFunctionsBll.replaceSpace(question), "solution":coursesFunctionsBll.replaceSpace(solution), "options":coursesFunctionsBll.replaceOptions(options)})
        return [jsonResponse]
    except Exception as er:
        return er
Beispiel #11
0
def centroidTriangleProblem():
    try:

        point = []
        while True:
            point = [
                [
                    random.randint(1, 10) * (random.randint(0, 1) * 2 - 1),
                    random.randint(1, 10) * (random.randint(0, 1) * 2 - 1)
                ],
                [
                    random.randint(1, 10) * (random.randint(0, 1) * 2 - 1),
                    random.randint(1, 10) * (random.randint(0, 1) * 2 - 1)
                ],
                [
                    random.randint(1, 10) * (random.randint(0, 1) * 2 - 1),
                    random.randint(1, 10) * (random.randint(0, 1) * 2 - 1)
                ]
            ]
            if (point[0][0] != point[1][0] and point[0][0] != point[2][0]
                    and point[1][0] != point[2][0]) and (
                        (point[0][1] != point[1][1]
                         and point[0][1] != point[2][1]
                         and point[1][1] != point[2][1])):
                #if (((point[0][1]+point[1][1])/(point[0][0]+point[1][0]))!=((point[0][1]+point[2][1])/(point[0][0]+point[2][0]))):
                break

        y1 = (point[0][1] + point[1][1]) / 2
        x1 = (point[0][0] + point[1][0]) / 2
        y2 = (point[0][1] + point[2][1]) / 2
        x2 = (point[0][0] + point[2][0]) / 2
        if x1 == point[2][0] or x2 == point[1][0]:
            return centroidTriangleProblem()
        m1 = (y1 - point[2][1]) / (x1 - point[2][0])
        c1 = point[2][1] - (m1 * point[2][0])
        m2 = (y2 - point[1][1]) / (x2 - point[1][0])
        if m1 == m2:
            return centroidTriangleProblem()
        c2 = point[1][1] - (m2 * point[1][0])
        x = round((c2 - c1) / (m1 - m2), 4)
        y = round((m2 * x) + c2, 4)

        solution = r"(" + str(x) + r"," + str(y) + r")"
        question = r"Find the centroid (median) of triangle with vertices at (" + str(
            point[0][0]) + r"," + str(point[0][1]) + r") (" + str(
                point[1][0]) + r"," + str(point[1][1]) + r") (" + str(
                    point[2][0]) + r"," + str(point[2][1]) + r"): "
        alternatives = coursesFunctionsBll.multiAritmeticOptions([x, y], 5)
        tempAlternatives = []
        for ta in range(5):
            tempAlternatives.append(r"(" + str(alternatives[ta][0]) + r"," +
                                    str(alternatives[ta][1]) + r")")
        options = json.loads(
            json.dumps({
                'a': tempAlternatives[0],
                'b': tempAlternatives[1],
                'c': tempAlternatives[2],
                'd': tempAlternatives[3],
                'e': tempAlternatives[4]
            }))
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er