The items a-d are to be paired with items 0-3 in such a way that the total distance between all item pairs are minimized. For example, this matrix could describe the distance between each item in the first group and an item in its counterpart group:
[[2, 2, 4, 9],
[4, 7, 1, 1],
[3, 3, 8, 3],
[6, 1, 7, 8]]
This is supposed to mean that the distance 'a' -> '0' is 2, from 'a' -> '1' is 2, from 'a' -> '2' is 4, 'a' -> '3' is 9. From 'b' -> '0' it is 4 and so on.
Is there an algorithm that can match each letter with a digit, so that the total distance is minimized? E.g.:
[('a', 1), ('b', 3), ('c', 0), ('d', 2)]
Would be a legal solution with total distance: 2 + 1 + 3 + 7 = 13. Brute forcing and testing all possible combinations is not possible since the real world has groups with much more than four items in them.