Павленко Дмитрий Юльевич, 411 группа SpiralString 9435
Жуков Александр Сергеевич SpiralString 10484
f1from collections import Counterf1from collections import Counter
22
3class Spiral:3class Spiral:
44
n5    def __init__(self, st):n5    def __init__(self, s):
6        if isinstance(st, str):6        if isinstance(s, str):
7            self.c = Counter(st)7            self.c = Counter(s)
8        else:8        else:
n9            self.c = stn9            self.c = s
1010
11    def __iter__(self):11    def __iter__(self):
12        for i in self.c.elements():12        for i in self.c.elements():
13            yield i13            yield i
1414
15    def __repr__(self):15    def __repr__(self):
n16        length = sum(self.c.values())n16        l = sum(self.c.values())
17        if length < 3:17        if l < 3:
18            return ''.join(list(self.c.elements()))18            return ''.join(list(self.c.elements()))
19        a_min = b_min = b_max = 019        a_min = b_min = b_max = 0
20        a_max = 120        a_max = 1
n21        direct = 0n21        dir_ = 0
22        x = 122        x = 1
23        y = 023        y = 0
n24        cnt = length - 1n24        cnt = l - 1
25        i = 225        i = 2
26        while cnt > i:26        while cnt > i:
n27            if direct == 0:n27            if dir_ == 0:
28                y -= i28                y -= i
29                b_min = min(y, b_min)29                b_min = min(y, b_min)
n30            elif direct == 1:n30            elif dir_ == 1:
31                x -= i31                x -= i
32                a_min = min(x, a_min)32                a_min = min(x, a_min)
n33            elif direct == 2:n33            elif dir_ == 2:
34                y += i34                y += i
35                b_max = max(y, b_max)35                b_max = max(y, b_max)
n36            elif direct == 3:n36            elif dir_ == 3:
37                x += i37                x += i
38                a_max = max(x, a_max)38                a_max = max(x, a_max)
39            cnt -= i39            cnt -= i
40            i += 140            i += 1
n41            direct = (direct + 1) % 4n41            dir_ = (dir_ + 1) % 4
42        cnt -= 142        cnt -= 1
n43        if direct == 0:n43        if dir_ == 0:
44            y -= cnt44            y -= cnt
45            b_min = min(y, b_min)45            b_min = min(y, b_min)
n46        elif direct == 1:n46        elif dir_ == 1:
47            x -= cnt47            x -= cnt
48            a_min = min(x, a_min)48            a_min = min(x, a_min)
n49        elif direct == 2:n49        elif dir_ == 2:
50            y += cnt50            y += cnt
51            b_max = max(y, b_max)51            b_max = max(y, b_max)
n52        elif direct == 3:n52        elif dir_ == 3:
53            x += cnt53            x += cnt
54            a_max = max(x, a_max)54            a_max = max(x, a_max)
55        a = a_max - a_min + 155        a = a_max - a_min + 1
56        b = b_max - b_min + 156        b = b_max - b_min + 1
57        x = -a_min57        x = -a_min
58        y = -b_min58        y = -b_min
59        matr = [[' ' for i in range(a)] for j in range(b)]59        matr = [[' ' for i in range(a)] for j in range(b)]
n60        direct = 0n60        dir_ = 0
61        i = j = 161        i = j = 1
62        for k in self.c.elements():62        for k in self.c.elements():
63            matr[y][x] = k63            matr[y][x] = k
n64            if direct == 0:n64            if dir_ == 0:
65                x += 165                x += 1
n66            elif direct == 1:n66            elif dir_ == 1:
67                y -= 167                y -= 1
n68            elif direct == 2:n68            elif dir_ == 2:
69                x -= 169                x -= 1
n70            elif direct == 3:n70            elif dir_ == 3:
71                y += 171                y += 1
72            if x < 0 or y < 0:72            if x < 0 or y < 0:
73                print('ERRRRRRROR')73                print('ERRRRRRROR')
74            j -= 174            j -= 1
75            if j == 0:75            if j == 0:
n76                direct = (direct + 1) % 4n76                dir_ = (dir_ + 1) % 4
77                i += 177                i += 1
78                j = i78                j = i
79        res = ''79        res = ''
80        for i in range(b):80        for i in range(b):
81            res += ''.join(matr[i]) + '\n'81            res += ''.join(matr[i]) + '\n'
82        return res82        return res
8383
n84    def __add__(self, other):n84    def __add__(self, sp):
85        return Spiral(self.c + other.c)85        return Spiral(self.c + sp.c)
8686
n87    def __sub__(self, other):n87    def __sub__(self, sp):
88        return Spiral(self.c - other.c)88        return Spiral(self.c - sp.c)
8989
90    def __mul__(self, num):90    def __mul__(self, num):
t91        tmp = Counter(self.c)t91        a = Counter(self.c)
92        for i in tmp:92        for i in a:
93            tmp[i] *= num93            a[i] *= num
94        return Spiral(tmp)94        return Spiral(a)
95'\nS = Spiral("abbcccddddeeeee")\nI = Spiral("abcdefghi")\n\nprint(f"{S}\n")\nprint(S+I, "\n")\nprint(S-I, "\n")\nprint(I*2, "\n")\nprint(I*2-S, "\n")\nprint(*list(S+I))\n'
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op