perm algorithms in python, with a slot object.
#permutation distinct element algorithm
#number of permutations:
import math
def perm_num(n):
return math.factorial(n)//math.factorial(n-n)
#number of appearances in each slot
def slot_events(k):
return perm_num(k)//k
def permutations(lst):
perm_template = []
perms = []
slot_max = slot_events(len(lst))
max_perms = perm_num(len(lst))
slot_counts = {x:[] for x in range(len(lst))}
####
class slot(object):
def __init__(self, value=None):
self.value = value
self.memo = []
if self.value:
self.memo.append(value)
def __repr__(self):
return str(self.value)
def __str__(self):
return str(self.value)
def change_val(self, other):
self.memo.append(other)
self.value = other