diff options
author | tanyaionova <isaqtm@gmail.com> | 2019-11-21 22:18:04 +0300 |
---|---|---|
committer | tanyaionova <isaqtm@gmail.com> | 2019-11-21 22:18:04 +0300 |
commit | 013924d56da2eef1d40f06e43f735b406fe2e2b1 (patch) | |
tree | 7113497b9915998e83d6a72cce0cd4c2606b7e72 /libsolve.py | |
parent | 275a6f805ecd7263bb4a8e0d495a19d237ee2f4d (diff) | |
download | alg2-013924d56da2eef1d40f06e43f735b406fe2e2b1.tar.gz |
Add first task
Diffstat (limited to 'libsolve.py')
-rw-r--r-- | libsolve.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/libsolve.py b/libsolve.py index 61d7f40..af72264 100644 --- a/libsolve.py +++ b/libsolve.py @@ -267,3 +267,16 @@ class Matrix: row.set_hints(max_hints) return '\n'.join(repr(row) for row in self.rows) + + +class Permutation: + def __init__(self, perm: Iterable): + self.perm = list(perm) + + def apply(self, now: list): + assert len(self.perm) == len(now) + res = [0] * len(self.perm) + for i in range(len(self.perm)): + res[self.perm[i]] = now[i] + + return res |