Created
September 27, 2022 00:53
-
-
Save madhadron/903d70295ef938d283d0f354999ca4f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| N = 4 # Number of chores | |
| p = 2 # Number of players | |
| preferences = [] | |
| for i in range(p): | |
| vs = list(range(N)) | |
| random.shuffle(vs) | |
| preferences.append(vs) | |
| def _vectors(xs, n_entries): | |
| if n_entries == 0: | |
| yield xs | |
| else: | |
| for i in range(p): | |
| for v in _vectors(xs+[i], n_entries-1): | |
| yield v | |
| def vectors(n_entries): | |
| return _vectors([], n_entries) | |
| def score(vs, preferences): | |
| sums = [0 for _ in preferences] | |
| for chore, person in enumerate(vs): | |
| rank = preferences[person][chore] | |
| sums[person] += rank | |
| return sum(x*x for x in sums) | |
| sorted_allocations = sorted(vectors(N), key=lambda vs: score(vs, preferences)) | |
| for vs in sorted_allocations: | |
| print(f'{score(vs, preferences)}\t{vs}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment