Даулетбек Досай 404 группа (КФ) CyberSausage 10966
Воробьев Егор Александрович, 419/2 (КФ) CyberSausage 10300
f1from fractions import Fractionf1from fractions import Fraction
2from math import floor2from math import floor
33
4class Sausage:4class Sausage:
n5    UNIT_VOLUME = 1n5    FULL_SIZE = 1
6    FILLING_LENGTH = 126    SLICE_SIZE = 12
77
n8    def __init__(self, filling='pork!', size='1'):n8    def __init__(self, stuffing='pork!', volume='1'):
9        self.filling = str(filling)9        self.stuffing = str(stuffing)
10        self.size = Fraction(size) if size else Fraction(0)10        self.volume = Fraction(volume) if volume else Fraction(0)
11        if self.size < 0:11        if self.volume < 0:
12            self.size = Fraction(0)12            self.volume = Fraction(0)
1313
14    def __repr__(self):14    def __repr__(self):
n15        if self.size * self.FILLING_LENGTH < 1:n15        if self.volume * self.SLICE_SIZE < 1:
16            return '/|\n||\n||\n||\n\\|'16            return '/|\n||\n||\n||\n\\|'
n17        full_units = floor(self.size)n17        full_sausages = floor(self.volume)
18        remainder_length = int(self.size % self.UNIT_VOLUME * self.FILLI18        partial_sausage_length = int(self.volume % self.FULL_SIZE * self
>NG_LENGTH)>.SLICE_SIZE)
19        sausages = []19        sausage_parts = []
20        for _ in range(full_units):20        for _ in range(full_sausages):
21            sausages.append(self._build_full_unit())21            sausage_parts.append(self._create_full_sausage())
22        if remainder_length > 0:22        if partial_sausage_length > 0:
23            sausages.append(self._build_partial_unit(remainder_length))23            sausage_parts.append(self._create_partial_sausage(partial_sa
 >usage_length))
24        return self._merge_units(sausages)24        return self._combine_sausages(sausage_parts)
2525
n26    def _build_full_unit(self):n26    def _create_full_sausage(self):
27        filling_content = (self.filling * (self.FILLING_LENGTH // len(se27        stuff = (self.stuffing * (self.SLICE_SIZE // len(self.stuffing) 
>lf.filling) + 1))[:self.FILLING_LENGTH]>+ 1))[:self.SLICE_SIZE]
28        return f'/------------\\\n|{filling_content}|\n|{filling_content28        return f'/------------\\\n|{stuff}|\n|{stuff}|\n|{stuff}|\n\\---
>}|\n|{filling_content}|\n\\------------/'>---------/'
2929
n30    def _build_partial_unit(self, filling_length):n30    def _create_partial_sausage(self, stuffing_length):
31        filling_content = (self.filling * (filling_length // len(self.fi31        stuff = (self.stuffing * (stuffing_length // len(self.stuffing) 
>lling) + 1))[:filling_length]>+ 1))[:stuffing_length]
32        return f'/{'-' * filling_length}|\n|{filling_content}|\n|{fillin32        return f'/{'-' * stuffing_length}|\n|{stuff}|\n|{stuff}|\n|{stuf
>g_content}|\n|{filling_content}|\n\\{'-' * filling_length}|'>f}|\n\\{'-' * stuffing_length}|'
3333
n34    def _merge_units(self, units):n34    def _combine_sausages(self, sausages):
35        rows = [unit.split('\n') for unit in units]35        rows = [sausage.split('\n') for sausage in sausages]
36        merged = [''.join(row) for row in zip(*rows)]36        combined = [''.join(row) for row in zip(*rows)]
37        return '\n'.join(merged)37        return '\n'.join(combined)
3838
39    def __abs__(self):39    def __abs__(self):
n40        return abs(self.size)n40        return abs(self.volume)
4141
42    def __add__(self, other):42    def __add__(self, other):
n43        combined_size = self.size + other.sizen43        new_volume = self.volume + other.volume
44        return Sausage(self.filling, max(combined_size, Fraction(0)))44        return Sausage(self.stuffing, max(new_volume, Fraction(0)))
4545
46    def __sub__(self, other):46    def __sub__(self, other):
n47        reduced_size = self.size - other.sizen47        new_volume = self.volume - other.volume
48        return Sausage(self.filling, max(reduced_size, Fraction(0)))48        return Sausage(self.stuffing, max(new_volume, Fraction(0)))
4949
n50    def __mul__(self, multiplier):n50    def __mul__(self, factor):
51        if isinstance(multiplier, int) and multiplier >= 0:51        if isinstance(factor, int) and factor >= 0:
52            return Sausage(self.filling, self.size * multiplier)52            return Sausage(self.stuffing, self.volume * factor)
53        raise ValueError('Multiplication multiplier must be a non-negati53        raise ValueError('Multiplication factor must be a non-negative i
>ve integer.')>nteger.')
5454
n55    def __rmul__(self, multiplier):n55    def __rmul__(self, factor):
56        return self.__mul__(multiplier)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:
n60            return Sausage(self.filling, self.size / divisor)n60            return Sausage(self.stuffing, self.volume / divisor)
61        raise ValueError('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):
t64        return self.size != 0t64        return self.volume != 0
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op