dimanche 7 novembre 2021

Maximize number of different values to avoid students cheating

So I will be giving an exam this fall which is an home exam. To avoid the students copying each other answers, I am going to randomize the values each student is given.

I want to maximize how different the exams are.

E.g if I count 1 every time two students got the same variant / variables and 0 otherwise, I want to minimize this sum for my number of students.

A toy example can be found below. Due note that my exam values are much more intricate, and depend on each other. Is there a better way than simply iterating over the values?

I thought about doing something like

a = random.shuffe(range(4, 11))

And then just iterating over a for every candidate, but it was difficult finding a starting point when one has over twenty variables, and not sure where the dependencies start.

from random import randint, randrange
import itertools


def exam_values():
    a = randint(4, 10)
    b = randrange(900, 1000, 25)
    c = randrange(b, 1000, a)
    d = randrange(a, c, 200)
    return a, b, c, d


def compare_students(A, B):
    return sum(1 if a == b else 0 for a, b in zip(A, B))


def compare_students_in_group(group):
    total = 0
    for pair in itertools.product(group, repeat=2):
        total += compare_students(*pair)
    return total


def optimize_students(students, samples=10 ** 4):
    best_group = [exam_values() for _ in students]
    best_group_score = compare_students_in_group(best_group)
    for _ in range(samples):
        group = [exam_values() for _ in students]
        group_score = compare_students_in_group(group)
        if group_score < best_group_score:
            print(group)
            print(best_group_score)
            best_group = group
            best_group_score = group_score
    return best_group


if __name__ == "__main__":
    students = list(range(100))
    samples = 10 ** 4
    optimize_students(students, samples)



Aucun commentaire:

Enregistrer un commentaire