How to apply matrices to dnd style games While playing a game, I needed to match 5 Characters to 5 Classes to optimise my team. I've listed the classes each character is suited for: Mage-2,4 Ninja-1,2 Thief-3,5 Warrior-1,2,4 Cleric-2,3,5. I'm vaguely guessing that matrices could be used to solve this.
My idea is (just a wild guess) if we assign values 1-5 for the characters too and create simultaneous equations with unknowns a-e representing the possible classes a character can take, i.e: a+2b+3c+4d+5e=k, we could create large matrices; solving would likely yield the best class matches for each character.
So,

*

*Anyone has an idea on how to solve this with maths?

*Could my idea work? Or is there some tweaking needed to my model?

 A: As I stated in my comment, what you are looking for is a perfect matching (or more generally, optimal perhaps) in a bipartite graph. There are several approaches that one can take to solving this problem; one of these is implemented in the Python "Network X" as the max_weight_matching method. Here is a script implementing this.
import networkx as nx

adj_dic = {
    'M':[2,4],
    'N':[1,2],
    'T':[3,5],
    'W':[1,2,4],
    'C':[2,3,5]
}

# generate graph from above data
G = nx.Graph()
for k,v in adj_dic.items():
    for n in v:
        G.add_edge(k,n)

# compute perfect matching (if one exists)
match = nx.max_weight_matching(G)

# generate visualization
import networkx as nx

left = 'MNTWC'
right = range(1,6)
pos = {}
for i,l,r in zip(range(5),left,right):
    pos[l] = (0,-i)
    pos[r] = (1,-i)
colors = ['red' if edge in match or edge[::-1] in match else 'black' for edge in G.edges()]
nx.draw(G, with_labels = True, node_color = 'orange', edge_color = colors, pos = pos)

The resulting visualization:

In other words, one solution is to pair classes to players as
1: warrior, 2: ninja, 3: cleric, 4: mage, 5: thief.
