Тюшев Максим, 321 PushPull 9365 | ПУТИЛОВ ГЕОРГИЙ КОНСТАНТИНОВИЧ PushPull 9999 | ||||
---|---|---|---|---|---|
t | 1 | class Pushpull: | t | 1 | class Pushpull: |
2 | pos = 0 | 2 | pos = 0 | ||
3 | 3 | ||||
4 | def __init__(self, p=0): | 4 | def __init__(self, p=0): | ||
5 | Pushpull.pos = p | 5 | Pushpull.pos = p | ||
6 | 6 | ||||
7 | @staticmethod | 7 | @staticmethod | ||
8 | def push(n=1): | 8 | def push(n=1): | ||
9 | Pushpull.pos += n | 9 | Pushpull.pos += n | ||
10 | 10 | ||||
11 | @staticmethod | 11 | @staticmethod | ||
12 | def pull(n=1): | 12 | def pull(n=1): | ||
13 | Pushpull.pos -= n | 13 | Pushpull.pos -= n | ||
14 | 14 | ||||
15 | def __str__(self): | 15 | def __str__(self): | ||
16 | if self.pos > 0: | 16 | if self.pos > 0: | ||
17 | return f'>{self.pos}>' | 17 | return f'>{self.pos}>' | ||
18 | elif self.pos < 0: | 18 | elif self.pos < 0: | ||
19 | return f'<{-self.pos}<' | 19 | return f'<{-self.pos}<' | ||
20 | return f'<{self.pos}>' | 20 | return f'<{self.pos}>' | ||
21 | 21 | ||||
22 | def __iter__(self): | 22 | def __iter__(self): | ||
23 | if self.pos > 0: | 23 | if self.pos > 0: | ||
24 | return iter(list(range(0, self.pos))) | 24 | return iter(list(range(0, self.pos))) | ||
25 | else: | 25 | else: | ||
26 | return iter([-i for i in range(0, -self.pos)]) | 26 | return iter([-i for i in range(0, -self.pos)]) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|