import random def is_sorted(l): for x in range(lengthlen(l)-1): if l[x] > l[x+1]: return False return True def score(length, index_chooser): steps = 0 l = list(range(length)) random.shuffle(l) while not is_sorted(l): i, j = index_chooser(length) assert (i < j) if l[i] > l[j]: l[i], l[j] = l[j], l[i] steps += 1 return steps