mardi 23 juillet 2019

Filling out a 2D array of pairs based on column and row criteria

I am trying to create a randomized 2D array based on 16 lists called "teams" of 13 elements each, where each element is a 2 character code for a "match up", or a combination of the name of the team and the name of one of the other teams. For example, "ab" represents a match up between team "a" and team "b". If list "a" has "ab", list "b" must also have a matching "ab" element representing that match up.

My goal is to create a 13 column 2D array where each column has each of the 16 teams play exactly one other team and all match ups for each team are used.

For example: If team "A" plays team "B" in the first column, no other team can play either team "A" or team "B" in that column and over the 13 columns team "A" must play teams "B", "C", "D" twice, teams "E", "F", "G", "H" once, and teams "J", "K", "L" once.

On top of that, I'd love for there to be an element of randomness to how the match ups for each team are arranged within the array so that different combinations of the columns can be generated while still maintaining the requirements. I was thinking that a greedy algorithm might be usable here, but I wasn't sure how to get started actually implementing one in this situation. Any suggested reading or articles are also appreciated.

Here is the total list of teams and match ups:

a: ['ab', 'ac', 'ad', 'ab', 'ac', 'ad', 'ae', 'af', 'ag', 'ah', 'aj', 'ak', 'al']
b: ['ab', 'bc', 'bd', 'ab', 'bc', 'bd', 'be', 'bf', 'bg', 'bh', 'bi', 'bk', 'bl']
c: ['ac', 'bc', 'cd', 'ac', 'bc', 'cd', 'ce', 'cf', 'cg', 'ch', 'ci', 'cj', 'cl']
d: ['ad', 'bd', 'cd', 'ad', 'bd', 'cd', 'de', 'df', 'dg', 'dh', 'di', 'dj', 'dk']
e: ['ef', 'eg', 'eh', 'ef', 'eg', 'eh', 'ae', 'be', 'ce', 'de', 'en', 'eo', 'ep']
f: ['ef', 'fg', 'fh', 'ef', 'fg', 'fh', 'af', 'bf', 'cf', 'df', 'fm', 'fo', 'fp']
g: ['eg', 'fg', 'gh', 'eg', 'fg', 'gh', 'ag', 'bg', 'cg', 'dg', 'gm', 'gn', 'gp']
h: ['eh', 'fh', 'gh', 'eh', 'fh', 'gh', 'ah', 'bh', 'ch', 'dh', 'hm', 'hn', 'ho']
i: ['ij', 'ik', 'il', 'ij', 'ik', 'il', 'im', 'in', 'io', 'ip', 'bi', 'ci', 'di']
j: ['ij', 'jk', 'jl', 'ij', 'jk', 'jl', 'jm', 'jn', 'jo', 'jp', 'aj', 'cj', 'dj']
k: ['ik', 'jk', 'kl', 'ik', 'jk', 'kl', 'km', 'kn', 'ko', 'kp', 'ak', 'bk', 'dk']
l: ['il', 'jl', 'kl', 'il', 'jl', 'kl', 'lm', 'ln', 'lo', 'lp', 'al', 'bl', 'cl']
m: ['mn', 'mo', 'mp', 'mn', 'mo', 'mp', 'im', 'jm', 'km', 'lm', 'fm', 'gm', 'hm']
n: ['mn', 'no', 'np', 'mn', 'no', 'np', 'in', 'jn', 'kn', 'ln', 'en', 'gn', 'hn']
o: ['mo', 'no', 'op', 'mo', 'no', 'op', 'io', 'jo', 'ko', 'lo', 'eo', 'fo', 'ho']
p: ['mp', 'np', 'op', 'mp', 'np', 'op', 'ip', 'jp', 'kp', 'lp', 'ep', 'fp', 'gp']

I know this question is pretty general and kind of weird so please let me know if I can clarify anything and thanks in advance!




Aucun commentaire:

Enregistrer un commentaire