Combinations resulting in high variance I have to fill in values at 8 places in a sequence such that the resulting sequences have high variance among them. The values are from the sets $A=${$255, 250, 220, 160$} and $P =${$0, 45, 90, 135, 180$}. First four values have to be filled in from $A$ and the remaining from $P$. 
I am trying to find a programmable solution in order to generate data from these values with maximum variance. 
An extension to this question is that the last 4 values taken from $P$ result in the same subsequence when difference between subsequent places is the same. For example __ __ __ __ 0 45 0 45 is the same as __ __ __ __ 45 90 45 90. If this can be accounted for, it would help a lot.  
 A: Here is the programmable (or, better to say, already programmed) solution to your problem. This Python program accepts the sizes of samples, that need to be taken from $A$ and $P$ and $A$ and $P$ themselves. It returns an example of the sequence with maximum variance and its variance:
import copy

def choice_with_replacement(n, A):
    if n == 0:
        yield []
    if n > 0:
        for l in choice_with_replacement(n-1, A):
            for a in A:
                ll = copy.deepcopy(l)
                ll.append(a)
                yield ll

def variance(A):
    return sum(list(map(lambda x:(x - sum(A)/len(A))**2, A)))/len(A)

n = int(input())
m = int(input())
A = list(map(int, input().split()))
P = list(map(int, input().split()))
varmax = -1
for a in choice_with_replacement(n, A):
    for b in choice_with_replacement(m, P):
        l = copy.deepcopy(a)
        l.extend(copy.deepcopy(b))
        var = variance(l)
        if var > varmax:
            varmax = var
            lmax = l
print(lmax, varmax)

