Жангирхан Шаку, 404 CyberSausage 10907
Воробьев Егор Александрович, 419/2 (КФ) CyberSausage 10300
f1from fractions import Fractionf1from fractions import Fraction
2from math import floor2from math import floor
33
4class Sausage:4class Sausage:
n5    FULL_UNIT = 1n5    FULL_SIZE = 1
6    SLICE_LENGTH = 126    SLICE_SIZE = 12
77
8    def __init__(self, stuffing='pork!', volume='1'):8    def __init__(self, stuffing='pork!', volume='1'):
9        self.stuffing = str(stuffing)9        self.stuffing = str(stuffing)
10        self.volume = Fraction(volume) if volume else Fraction(0)10        self.volume = Fraction(volume) if volume else Fraction(0)
11        if self.volume < 0:11        if self.volume < 0:
12            self.volume = Fraction(0)12            self.volume = Fraction(0)
1313
14    def __repr__(self):14    def __repr__(self):
n15        if self.volume * self.SLICE_LENGTH < 1:n15        if self.volume * self.SLICE_SIZE < 1:
16            return '/|\n||\n||\n||\n\\|'16            return '/|\n||\n||\n||\n\\|'
n17        full_sausages_count = floor(self.volume)n17        full_sausages = floor(self.volume)
18        remaining_sausage_length = int(self.volume % self.FULL_UNIT * se18        partial_sausage_length = int(self.volume % self.FULL_SIZE * self
>lf.SLICE_LENGTH)>.SLICE_SIZE)
19        sausage_parts = []19        sausage_parts = []
n20        for _ in range(full_sausages_count):n20        for _ in range(full_sausages):
21            sausage_parts.append(self._create_full_baton())21            sausage_parts.append(self._create_full_sausage())
22        if remaining_sausage_length > 0:22        if partial_sausage_length > 0:
23            sausage_parts.append(self._create_partial_baton(remaining_sa23            sausage_parts.append(self._create_partial_sausage(partial_sa
>usage_length))>usage_length))
24        return self._combine_parts(sausage_parts)24        return self._combine_sausages(sausage_parts)
2525
n26    def _create_full_baton(self):n26    def _create_full_sausage(self):
27        stuffing_repeat = (self.stuffing * (self.SLICE_LENGTH // len(sel27        stuff = (self.stuffing * (self.SLICE_SIZE // len(self.stuffing) 
>f.stuffing) + 1))[:self.SLICE_LENGTH]>+ 1))[:self.SLICE_SIZE]
28        return f'/------------\\\n|{stuffing_repeat}|\n|{stuffing_repeat28        return f'/------------\\\n|{stuff}|\n|{stuff}|\n|{stuff}|\n\\---
>}|\n|{stuffing_repeat}|\n\\------------/'>---------/'
2929
n30    def _create_partial_baton(self, stuffing_length):n30    def _create_partial_sausage(self, stuffing_length):
31        stuffing_repeat = (self.stuffing * (stuffing_length // len(self.31        stuff = (self.stuffing * (stuffing_length // len(self.stuffing) 
>stuffing) + 1))[:stuffing_length]>+ 1))[:stuffing_length]
32        return f'/{'-' * stuffing_length}|\n|{stuffing_repeat}|\n|{stuff32        return f'/{'-' * stuffing_length}|\n|{stuff}|\n|{stuff}|\n|{stuf
>ing_repeat}|\n|{stuffing_repeat}|\n\\{'-' * stuffing_length}|'>f}|\n\\{'-' * stuffing_length}|'
3333
t34    def _combine_parts(self, parts):t34    def _combine_sausages(self, sausages):
35        rows = [part.split('\n') for part in parts]35        rows = [sausage.split('\n') for sausage in sausages]
36        combined = [''.join(row) for row in zip(*rows)]36        combined = [''.join(row) for row in zip(*rows)]
37        return '\n'.join(combined)37        return '\n'.join(combined)
3838
39    def __abs__(self):39    def __abs__(self):
40        return abs(self.volume)40        return abs(self.volume)
4141
42    def __add__(self, other):42    def __add__(self, other):
43        new_volume = self.volume + other.volume43        new_volume = self.volume + other.volume
44        return Sausage(self.stuffing, max(new_volume, Fraction(0)))44        return Sausage(self.stuffing, max(new_volume, Fraction(0)))
4545
46    def __sub__(self, other):46    def __sub__(self, other):
47        new_volume = self.volume - other.volume47        new_volume = self.volume - other.volume
48        return Sausage(self.stuffing, max(new_volume, Fraction(0)))48        return Sausage(self.stuffing, max(new_volume, Fraction(0)))
4949
50    def __mul__(self, factor):50    def __mul__(self, factor):
51        if isinstance(factor, int) and factor >= 0:51        if isinstance(factor, int) and factor >= 0:
52            return Sausage(self.stuffing, self.volume * factor)52            return Sausage(self.stuffing, self.volume * factor)
53        raise ValueError('Multiplication factor must be a non-negative i53        raise ValueError('Multiplication factor must be a non-negative i
>nteger.')>nteger.')
5454
55    def __rmul__(self, factor):55    def __rmul__(self, factor):
56        return self.__mul__(factor)56        return self.__mul__(factor)
5757
58    def __truediv__(self, divisor):58    def __truediv__(self, divisor):
59        if isinstance(divisor, int) and divisor > 0:59        if isinstance(divisor, int) and divisor > 0:
60            return Sausage(self.stuffing, self.volume / divisor)60            return Sausage(self.stuffing, self.volume / divisor)
61        raise ValueError('Division divisor must be a positive integer.')61        raise ValueError('Division divisor must be a positive integer.')
6262
63    def __bool__(self):63    def __bool__(self):
64        return self.volume != 064        return self.volume != 0
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op