def mslq_encode(answers, num):
    """Function that receives an array of 44 answers and encodes the results
    for the MSLQ survey. It returns the following tuple:

    (IVAL: Intrinsic value,
     SEFF: Self-efficacy,
     TANX: Test anxiety,
     CSUS: Cognitive strategy use,
     SREL: Self-regulation)

    They are the averages of the corresponding questions.

    :param answers: Array of 44 integers encoding the answers
    :param num: Number of possibe answers in each question
    """
    ival_idx = [1, 4, 5, 7, 10, 14, 15, 17, 21]
    seff_idx = [2, 6, 8, 9, 11, 13, 16, 18, 19]
    tanx_idx = [3, 12, 20, 22]
    csus_idx = [23, 24, 26, 28, 29, 30, 31, 34, 36, 39, 41, 42, 44]
    srel_idx = [25, 27, 32, 33, 35, 37, 38, 40, 43]

    # Items with reverse encoding
    reverse_idx = [26, 27, 37, 38]

    # Apply the reverse encoding
    for idx in reverse_idx:
        answers[idx] = num + 1 - answers[idx]

    # Calculate and return the five values
    return (1.0 * sum([answers[i - 1] for i in ival_idx]) / len(ival_idx),
            1.0 * sum([answers[i - 1] for i in seff_idx]) / len(seff_idx),
            1.0 * sum([answers[i - 1] for i in tanx_idx]) / len(tanx_idx),
            1.0 * sum([answers[i - 1] for i in csus_idx]) / len(csus_idx),
            1.0 * sum([answers[i - 1] for i in srel_idx]) / len(srel_idx))