Quiz matrix with two parts scoring system

Viewed 98

I hope I'm on the right place, because I'm lossing my mind, trying to get one quiz together.

So the thing is that I need to setup score based system for quiz. I have two sections of questions (1-13 and 14-21). Rules are:

Questions 1-13: if six or more answers are Answer 3 or Answer 4
Questions 14-21: if six or more answers are Answer 3 or Answer 4
is OPTION 1

Questions 1-13: if six or more answers are Answer 3 or Answer 4
Questions 14-21: if less than six answers are Answer 3 or Answer 4
is OPTION 2

If there are less than five answers with Answer 3 or Answer 4 in each set of questions
is OPTION 3

Now I need some system for scoring. In my program I have option for +,-,/,* between answers, but I can't come with working solution. Scores on each answer can be negative too. I'm limited with programing, because I can do only basic math expressions and not actual programming like if this, then this.

Answer 0 Answer 1 Answer 2 Answer 3 Answer 4
Question 1 0 0 0 x x
Question 2 0 0 0 x x
Question 3 0 0 0 x x
Question 4 0 0 0 x x
Question 5 0 0 0 x x
Question 6 0 0 0 x x
Question 7 0 0 0 x x
Question 8 0 0 0 x x
Question 9 0 0 0 x x
Question 10 0 0 0 x x
Question 11 0 0 0 x x
Question 12 0 0 0 x x
Question 13 0 0 0 x x
Question 14 0 0 0 x x
Question 15 0 0 0 x x
Question 16 0 0 0 x x
Question 17 0 0 0 x x
Question 18 0 0 0 x x
Question 19 0 0 0 x x
Question 20 0 0 0 x x
Question 21 0 0 0 x x

Answers 0, 1 and 2 are not important so I placed 0 there.

Thanks in advance for any suggestions/help!

1 Answers

It's hard to give more advice without knowing what programming language you want to write this in and without an example.

The partial solution below should at least get you started. It is only using basic math expressions +,-,/,*, and additionally the absolute value |n| (otherwise the solution is close to impossible). Note that the for loops are just a shorthand for a chain of additions.

The caveat with this solution is that it breaks if there are exactly 6 answers 3 and 4. I can update this if you give more details as to what operators you have available.

// Assuming one correct answer
// 1 = Answer was selected, 0 = not selected
const answers = [
    //        Answer 3 | Answer 4
    /* Q1  */[    1    ,    0   ],
    /* Q2  */[    1    ,    0   ],
    /* Q3  */[    1    ,    0   ],
    /* Q4  */[    0    ,    1   ],
    /* Q5  */[    1    ,    0   ],
    /* Q6  */[    0    ,    1   ],
    /* Q7  */[    1    ,    0   ],
    /* Q8  */[    1    ,    0   ],
    /* Q9  */[    0    ,    1   ],
    /* Q10 */[    0    ,    1   ],
    /* Q11 */[    0    ,    1   ],
    /* Q12 */[    1    ,    0   ],
    /* Q13 */[    0    ,    0   ],

    /* Q14 */[    0    ,    1   ],
    /* Q15 */[    1    ,    0   ],
    /* Q16 */[    0    ,    0   ],
    /* Q17 */[    0    ,    1   ],
    /* Q18 */[    0    ,    0   ],
    /* Q19 */[    1    ,    0   ],
    /* Q20 */[    1    ,    0   ],
    /* Q21 */[    0    ,    0   ],
];

// Calculate option

// 1. Count answers 3 or 4 in Q1-Q13
let count_1_13 = 0; 
for (let i = 0; i < 13; ++i) {
    count_1_13 += answers[i][0] + answers[i][1];
}
console.log(`Questions 1-13: ${count_1_13} answers 3 or 4`);

// 2. Count answers 3 or 4 in Q14-Q21
let count_14_21 = 0; 
for (let i = 13; i < 21; ++i) {
    count_14_21 += answers[i][0] + answers[i][1];
}
console.log(`Questions 4-21: ${count_14_21} answers 3 or 4`);

// 3. Subtract 6
// If there are 6 or more answers, the count will stay positive,
// otherwise it will become negative.
count_1_13 = count_1_13 - 6;
count_14_21 = count_14_21 - 6;

// 4. Find the weight (0 for positive, 1 for negative)
// Caveat: if there are exactly 6 answers, this breaks (division by zero)
const sign_1_13 = (1 - count_1_13 / Math.abs(count_1_13)) / 2;
const sign_14_21 = (1 - count_14_21 / Math.abs(count_14_21)) / 2;

let option = 1;
option += sign_1_13;
option += sign_14_21;

console.log(`Result: Option ${option}`);

// Arbitrary scores for each question
const scores = [
    //        Answer 3 | Answer 4
    /* Q1  */[    5    ,    2   ],
    /* Q2  */[   -2    ,    9   ],
    /* Q3  */[    3    ,   -1   ],
    /* Q4  */[    5    ,    1   ],
    /* Q5  */[    1    ,    2   ],
    /* Q6  */[    5    ,    1   ],
    /* Q7  */[   -1    ,    5   ],
    /* Q8  */[    1    ,    1   ],
    /* Q9  */[    1    ,    7   ],
    /* Q10 */[   -6    ,    3   ],
    /* Q11 */[    5    ,    1   ],
    /* Q12 */[    6    ,    7   ],
    /* Q13 */[    5    ,   -4   ],

    /* Q14 */[    7    ,    3   ],
    /* Q15 */[   -1    ,   -2   ],
    /* Q16 */[    1    ,    1   ],
    /* Q17 */[    5    ,    5   ],
    /* Q18 */[    1    ,    1   ],
    /* Q19 */[    2    ,    6   ],
    /* Q20 */[    2    ,   -4   ],
    /* Q21 */[    4    ,    8   ],
];

// Calculate score
let totalScore = 0;
for (let i = 0; i < scores.length; ++i) {
    totalScore += scores[i][0] * answers[i][0] + scores[i][1] * answers[i][1];
}
console.log(`Total score: ${totalScore}`);

Related