# This is a script that generates permutations,
# given a list of outcomes and the size of the sequences.
# A permutation is when we calculate all possible sequences where 
# it's not allowed to have a repeated outcome inside each sequence.
# For example if all possible outcomes are 1 and 2 and we want to generates
# all possible sequences, given the sequence size is 2 outcomes, we'll end up
# with two possible permutations: (1, 2) , (2, 1). 
# Since (1, 1) and (2, 2) both contain repeated outcome,
# they're not considered permutaions.
# The script is written in Python3.4

def calcperm(arr, size):
    result = set([()])
    for dummy_idx in range(size):
        temp = set()
        for dummy_lst in result:
            for dummy_outcome in arr:
                if dummy_outcome not in dummy_lst:
                    new_seq = list(dummy_lst)
        result = temp
    return result

# Test Cases:

lst = [1, 2, 3, 4]
#lst = ["yellow", "magenta", "white", "blue"]
seq = 2
final = calcperm(lst, seq)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s