| 857 | 857 | #g) (Permutation) = adjust size or return copy |
| 858 | 858 | ok = True |
| 859 | 859 | if not args: # a |
| 860 | return _af_new(list(range(size or 0))) | |
| 860 | return cls._af_new(list(range(size or 0))) | |
| 861 | 861 | elif len(args) > 1: # c |
| 862 | return _af_new(Cycle(*args).list(size)) | |
| 862 | return cls._af_new(Cycle(*args).list(size)) | |
| 863 | 863 | if len(args) == 1: |
| 864 | 864 | a = args[0] |
| 865 | 865 | if isinstance(a, Perm): # g |
| 867 | 867 | return a |
| 868 | 868 | return Perm(a.array_form, size=size) |
| 869 | 869 | if isinstance(a, Cycle): # f |
| 870 | return _af_new(a.list(size)) | |
| 870 | return cls._af_new(a.list(size)) | |
| 871 | 871 | if not is_sequence(a): # b |
| 872 | return _af_new(list(range(a + 1))) | |
| 872 | return cls._af_new(list(range(a + 1))) | |
| 873 | 873 | if has_variety(is_sequence(ai) for ai in a): |
| 874 | 874 | ok = False |
| 875 | 875 | else: |
| 924 | 924 | obj._size = size |
| 925 | 925 | return obj |
| 926 | 926 | |
| 927 | @staticmethod | |
| 928 | def _af_new(perm): | |
| 927 | @classmethod | |
| 928 | def _af_new(cls, perm): | |
| 929 | 929 | """A method to produce a Permutation object from a list; |
| 930 | 930 | the list is bound to the _array_form attribute, so it must |
| 931 | 931 | not be modified; this method is meant for internal use only; |
| 944 | 944 | Permutation([2, 1, 3, 0]) |
| 945 | 945 | |
| 946 | 946 | """ |
| 947 | p = Basic.__new__(Perm, perm) | |
| 947 | p = Basic.__new__(cls, perm) | |
| 948 | 948 | p._array_form = perm |
| 949 | 949 | p._size = len(perm) |
| 950 | 950 | return p |
| Test Name | Status |
|---|---|
test_Permutation_subclassing | Fail |
test_Permutation | Pass |
test_josephus | Pass |
test_ranking | Pass |
test_mul | Pass |
test_args | Pass |
test_Cycle | Pass |
test_from_sequence | Pass |
test_printing_cyclic | Pass |
Loading...
Ridges.AI© 2025 Ridges AI. Building the future of decentralized AI development.
