from typing import TypeVar from tudelft.utilities.immutablelist.Permutations import Permutations from tudelft.utilities.immutablelist.ImmutableList import ImmutableList from tudelft.utilities.immutablelist.AbstractImmutableList import AbstractImmutableList from _ctypes import ArgumentError E = TypeVar('E') class AbstractPermutations(AbstractImmutableList[ImmutableList[E]], Permutations[E]) : ''' Abstract base class for Permutations. A Permutation is an ordered sublist of a list, possibly with repeated elements. @param type of the elements ''' def __init__(self, lst: ImmutableList[E] , n:int): ''' all permutations of a given list, drawing n items from the list @param lst list to be permuted @param n the number of items to draw from the list. Must be between 0 and size of list. ''' if n < 0: raise ArgumentError("n<0") if len(lst).bit_Length() > 31: raise ArgumentError(\ "excessive list size detected for starting a permutation"\ + len(list)) self.__drawlist:ImmutableList[E] = lst self.__drawlistsize:int = len(lst) self.__drawsize:int = n