I don't understand kumites, so sorry if this isn't what you wanted
Original Description:
If we have planty of objects like this: ['a', 'b', 'c']
then we can build all permutation:
0 – abc
1 – acb
2 – bac
3 – bca
4 – cab
5 – cba
Any of them permutations may be calculated by their index number without calculated others.
from itertools import permutations def SequencePermutation(plenty, count): ret = list(permutations(plenty, count)) return ret
import math- from itertools import permutations
- def SequencePermutation(plenty, count):
- ret = list(permutations(plenty, count))
- return ret
class SequencePermutation(object):def __init__(self, plenty_object, count_item):self.plenty_object = list(plenty_object)self.count_item = count_itemself.power_plenty = len(plenty_object)@staticmethoddef calc_count_permutation(n, k):return int(math.factorial(n) / math.factorial(n - k))def __getitem__(self, index):current_mod = indexplenty = self.plenty_object.copy()for i in range(self.count_item - 1):perm_count = self.calc_count_permutation(self.power_plenty - i - 1, self.count_item - i - 1)current_index = current_mod // perm_countyield plenty[current_index]plenty.pop(current_index)current_mod = current_mod % perm_countyield plenty[current_mod]