## Combinatoric commanders

For the discussion of math. Duh.

Moderators: gmalivuk, Moderators General, Prelates

fealuinix
Posts: 42
Joined: Sat Jun 14, 2008 12:39 pm UTC

### Combinatoric commanders

Imagine five colors on a wheel--white, blue, black, red, and green, looping back to white.  I have 20 cards with some of those colors on each.  5 have four of the colors, each missing a different one.  5 have two colors; 1 of each possible combination of colors next to each other on the wheel (white-blue, blue-black, etc.)  10 have two colors that are not next to each other; 2 distinct cards for each possible color combination.  How many ways can I make 5 piles of cards where each pile has exactly four colors, each pile is missing a different color, and each pile consists of either 1 four-color card, or 2 two-color cards?

Some of you may recognize that what I'm really asking is "If I have one of each of the 2016 MTG Commander decks, how many ways can I swap around the commanders for all five decks?"

Lothario O'Leary
Posts: 41
Joined: Fri Feb 05, 2016 3:39 pm UTC

### Re: Combinatoric commanders

I tried to do it by listing the possible cases, but it's really complicated. I'd try a program, but I'm not that good of a programmer.
It looks like the answer is somewhere around 20000, however.

PM 2Ring
Posts: 3689
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Sydney, Australia

### Re: Combinatoric commanders

I'll represent the colors by their initials, except I'll use the printers' convention of using K for black, so our colors in color-wheel order are WBKRG.

The 5 four-color cards are

BKRG WKRG WBRG WBKG WBKR

The 15 two-color cards are

WB BK KR RG GW WK KW WR RW BR RB BG GB KG GK

For each color there are 7 two-color pairs that do not contain that color. Here are the pairs that don't contain W:

BK+RG
BR+GK
BR+KG
KR+BG
KR+GB
RB+GK
RB+KG

Thus for a given color there are 1 + 7 = 8 different ways to make a pile that doesn't contain that color since we can either choose the appropriate four-colour card or one of the 7 two-colour pairs.

Now things start to get tricky.

Here's some Python code that does a brute force search of the 85 = 32768 combinations looking for ones that don't reuse any two-color cards. It finds 5915 different ways to make the piles.

This code runs on Python 3 or Python 2.7; with slight modifications it can run on older versions of Python 2.

Code: Select all

`from __future__ import print_functionfrom itertools import combinations, productcolors = 'WBKRG'colorset = set(colors)print(colors)# Four-color cardscol4 = [colors[:i] + colors[i+1:] for i in range(len(colors))]print(*col4)groups = {k: [(u,)] for k, u in zip(colors, col4)}# Two-color adjacentscol2 = [u + v for u, v in zip(colors, colors[1:] + colors[:1])]# Add the two-color non-adjacentsfor u, v in combinations(colors, 2):    a, b = u + v, v + u    if not (a in col2 or b in col2):        col2.extend((a, b))print(*col2)pairs = []for u, v in combinations(col2, 2):    k = colorset - set(u + v)    if len(k) == 1:        pairs.append((k.pop(), (u, v)))pairs.sort()for k, t in pairs:    groups[k].append(t)for k in colors:    print(k, groups[k])# Generate valid pilesgood = 0for piles in product(*[groups[k] for k in colors]):    used = set()    for t in piles:        if len(t) == 2:            s = set(t)            if not used.intersection(s):                used.update(s)            else:                break    else:        #print(piles)        good += 1print('\nNumber of ways to make the piles =', good)`

Output:

Code: Select all

`WBKRGBKRG WKRG WBRG WBKG WBKRWB BK KR RG GW WK KW WR RW BR RB BG GB KG GKW [('BKRG',), ('BK', 'RG'), ('BR', 'GK'), ('BR', 'KG'), ('KR', 'BG'), ('KR', 'GB'), ('RB', 'GK'), ('RB', 'KG')]B [('WKRG',), ('KR', 'GW'), ('RG', 'KW'), ('RG', 'WK'), ('RW', 'GK'), ('RW', 'KG'), ('WR', 'GK'), ('WR', 'KG')]K [('WBRG',), ('GW', 'BR'), ('GW', 'RB'), ('RW', 'BG'), ('RW', 'GB'), ('WB', 'RG'), ('WR', 'BG'), ('WR', 'GB')]R [('WBKG',), ('BK', 'GW'), ('KW', 'BG'), ('KW', 'GB'), ('WB', 'GK'), ('WB', 'KG'), ('WK', 'BG'), ('WK', 'GB')]G [('WBKR',), ('BK', 'RW'), ('BK', 'WR'), ('KW', 'BR'), ('KW', 'RB'), ('WB', 'KR'), ('WK', 'BR'), ('WK', 'RB')]Number of ways to make the piles = 5915`

To get this code to actually list all of the piles just uncomment the #print(piles) line.

Sizik
Posts: 1242
Joined: Wed Aug 27, 2008 3:48 am UTC

### Re: Combinatoric commanders

PM 2Ring wrote:I'll represent the colors by their initials, except I'll use the printers' convention of using K for black, so our colors in color-wheel order are WBKRG.

The official convention is to use B for black and U for blue.
gmalivuk wrote:
King Author wrote:If space (rather, distance) is an illusion, it'd be possible for one meta-me to experience both body's sensory inputs.
Yes. And if wishes were horses, wishing wells would fill up very quickly with drowned horses.

Demki
Posts: 199
Joined: Fri Nov 30, 2012 9:29 pm UTC

### Re: Combinatoric commanders

Sizik wrote:
PM 2Ring wrote:I'll represent the colors by their initials, except I'll use the printers' convention of using K for black, so our colors in color-wheel order are WBKRG.

The official convention is to use B for black and U for blue.

PM 2Ring refers to the CMYK color model, where K stands for Key and is the black color.
In fact, B is quite commonly used for Blue, as in the RGB color model

WibblyWobbly
Can't Get No
Posts: 506
Joined: Fri Apr 05, 2013 1:03 pm UTC

### Re: Combinatoric commanders

Demki wrote:
Sizik wrote:
PM 2Ring wrote:I'll represent the colors by their initials, except I'll use the printers' convention of using K for black, so our colors in color-wheel order are WBKRG.

The official convention is to use B for black and U for blue.

PM 2Ring refers to the CMYK color model, where K stands for Key and is the black color.
In fact, B is quite commonly used for Blue, as in the RGB color model

Sizik is referring to the long-standing convention in M:tG. Which is more or less the way WotC did it way back in the long long ago (at least, since I started, which was during the Revised/Third Ed. era)

PM 2Ring
Posts: 3689
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Sydney, Australia

### Re: Combinatoric commanders

Sizik wrote:
PM 2Ring wrote:I'll represent the colors by their initials, except I'll use the printers' convention of using K for black, so our colors in color-wheel order are WBKRG.

The official convention is to use B for black and U for blue.

Ah, ok. I'm not really into Pokémon I don't know much about M:tG.

If you want to run my code using that convention just change the color assignment line from

Code: Select all

`colors = 'WBKRG'`

to

Code: Select all

`colors = 'WUBRG'`