def _assure_length(self, l): if l in self.permutations: return if l == 0: self.permutations[0] = [] maybe = Permutation([]) if maybe.avoids(*self.avoidance): self.permutations[0].append(maybe) else: self._assure_length(l-1) here = set() for p in self.permutations[l-1]: for i in range(l): q = Permutation(p[:i] + (l,) + p[i:]) if q.avoids(*self.avoidance): here.add(q) self.permutations[l] = list(here)
def _assure_length(self, l): if l in self.permutations: return if l == 0: self.permutations[0] = [] maybe = Permutation([]) if maybe.avoids(*self.avoidance): self.permutations[0].append(maybe) else: self._assure_length(l - 1) here = set() for p in self.permutations[l - 1]: for i in range(l): q = Permutation(p[:i] + (l, ) + p[i:]) if q.avoids(*self.avoidance): here.add(q) self.permutations[l] = here