Exemple #1
0
def get_answers(questions: List[QuizSubmissionQuestion]) -> List[Dict]:
    """Creates answers for Canvas quiz questions"""

    answer_0 = {
        "fib_100000": last_8(optimized_fibonacci(100000)),
        "summable_5_7_11_100000": last_8(SummableSequence(5, 7, 11)(100000)),
        "summable_0_1_100000": last_8(SummableSequence(0, 1)(100000)),
        "fib_234202": last_8(optimized_fibonacci(234202)),
        "summable_8_9_99_141515": last_8(SummableSequence(8, 9, 99)(141515)),
        "summable_5_98_7_35_2_603":
        last_8(SummableSequence(5, 98, 7, 35, 2)(603)),
    }
    answer_1 = {
        "pyramid_24":
        hashlib.sha256(pyramid_extract(24).encode()).hexdigest()[:8],
        "pyramid_53":
        hashlib.sha256(pyramid_extract(53).encode()).hexdigest()[:8],
    }
    answer_2 = 8610

    answers = [answer_0, answer_1, answer_2]

    results = []
    for i in range(len(questions)):
        results.append({"id": questions[i].id, "answer": answers[i]})
    return results
Exemple #2
0
def build_answer_sequence(question) -> Dict:
    """Generates a response dict for fib & sequence question

    :param question question: the question for which we will build a response
    :rtype: dict
    """
    answer_dict = {}
    for answ in question.answer:
        components = answ.split("_")
        op_type = components.pop(0)
        loops = int(components.pop())
        starting_seq = tuple(map(int, components))

        if op_type == "summable":
            new_seq = fibonacci.SummableSequence(*starting_seq)
            # print("new_seq(100000)[-8:]:", fibonacci.last_8(new_seq(loops)))  # 60500327
            answer_dict[answ] = fibonacci.last_8(new_seq(loops))
        elif op_type == "fib":
            # print(fibonacci.last_8(fibonacci.optimized_fibonacci(loops)))
            answer_dict[answ] = fibonacci.last_8(fibonacci.optimized_fibonacci(loops))
    # return_dict = {"id": question.id, "answer": answer_dict}
    # print(return_dict)
    return {"id": question.id, "answer": answer_dict}
Exemple #3
0
 def test_8(self):
     self.assertEqual("123", last_8(123))
     self.assertEqual("23456789", last_8(123456789))
 def test_8(self):
     self.assertEqual(123, last_8(123))
     self.assertEqual(23456789, last_8(123456789))
 def test_last8(self):
     for n, expected in [(1234567890, 34567890), (1, 1),
                         (12345678, 12345678)]:
         with timeout(message="Timeout running f({})".format(n)):
             self.assertEqual(last_8(n), expected)
Exemple #6
0
def get_answers(questions: List[QuizSubmissionQuestion]) -> List[Dict]:
    """Creates answers for Canvas quiz questions"""
    # Formulate your answers - see docs for QuizSubmission.answer_submission_questions below
    # It should be a list of dicts, one per q, each with an 'id' and 'answer' field
    # The format of the 'answer' field depends on the question type
    # You are responsible for collating questions with the functions to call - do not hard code

    # submission list
    submission = []

    # answering fib/summable questions
    answers = {}

    # optimised fibonacci questions
    answers["fib_100000"] = last_8(optimized_fibonacci(100000))
    answers["fib_234202"] = last_8(optimized_fibonacci(234202))

    # summable questions
    seq = SummableSequence(0, 1)
    answers["summable_0_1_100000"] = last_8(seq(100000))

    seq = SummableSequence(5, 7, 11)
    answers["summable_5_7_11_100000"] = last_8(seq(100000))

    seq = SummableSequence(5, 98, 7, 35, 2)
    answers["summable_5_98_7_35_2_603"] = last_8(seq(603))

    seq = SummableSequence(8, 9, 99)
    answers["summable_8_9_99_141515"] = last_8(seq(141515))

    tmp = {"id": questions[0].id, "answer": answers}
    submission.append(tmp)

    # answering pyramid questions
    answers = {}

    # anwser for pyramid_24
    with capture_print() as std:
        print_pyramid(24)
    std.seek(0)
    output = std.read()
    output = hashlib.sha256(output.encode()).hexdigest()
    answers["pyramid_24"] = output[:8]

    # anwser for pyramid_53
    with capture_print() as std:
        print_pyramid(53)
    std.seek(0)
    output = std.read()
    output = hashlib.sha256(output.encode()).hexdigest()
    answers["pyramid_53"] = output[:8]

    tmp = {"id": questions[1].id, "answer": answers}

    submission.append(tmp)

    # answering time question
    tmp = {"id": questions[2].id, "answer": 3268}
    submission.append(tmp)

    # eg {"id": questions[0].id, "answer": {key: some_func(key) for key in questions[0].answer.keys()}}
    return submission