Алдабергенов Руслан Даниярович, 411 CyberSausage 10972
Воробьев Егор Александрович, 419/2 (КФ) CyberSausage 10300
f1from fractions import Fractionf1from fractions import Fraction
2from math import floor2from math import floor
33
4class Sausage:4class Sausage:
n5    FILLING_SIZE = 12n5    FULL_SIZE = 1
6    UNIT_VOLUME = 16    SLICE_SIZE = 12
77
n8    def __init__(self, filling='pork!', quantity='1'):n8    def __init__(self, stuffing='pork!', volume='1'):
9        self.filling = str(filling)9        self.stuffing = str(stuffing)
10        self.quantity = Fraction(quantity) if quantity else Fraction(0)10        self.volume = Fraction(volume) if volume else Fraction(0)
11        self.quantity = max(self.quantity, Fraction(0))11        if self.volume < 0:
12            self.volume = Fraction(0)
1213
13    def __repr__(self):14    def __repr__(self):
n14        if self.quantity * self.FILLING_SIZE < 1:n15        if self.volume * self.SLICE_SIZE < 1:
15            return '/|\n||\n||\n||\n\\|'16            return '/|\n||\n||\n||\n\\|'
n16        full_buns = floor(self.quantity)n17        full_sausages = floor(self.volume)
17        partial_bun_length = int(self.quantity % self.UNIT_VOLUME * self18        partial_sausage_length = int(self.volume % self.FULL_SIZE * self
>.FILLING_SIZE)>.SLICE_SIZE)
18        buns = []19        sausage_parts = []
19        for _ in range(full_buns):20        for _ in range(full_sausages):
20            buns.append(self._generate_full_bun())21            sausage_parts.append(self._create_full_sausage())
21        if partial_bun_length > 0:22        if partial_sausage_length > 0:
22            buns.append(self._generate_partial_bun(partial_bun_length))23            sausage_parts.append(self._create_partial_sausage(partial_sa
 >usage_length))
23        return self._combine_buns(buns)24        return self._combine_sausages(sausage_parts)
2425
n25    def _generate_full_bun(self):n26    def _create_full_sausage(self):
26        filling_content = (self.filling * (self.FILLING_SIZE // len(self27        stuff = (self.stuffing * (self.SLICE_SIZE // len(self.stuffing) 
>.filling) + 1))[:self.FILLING_SIZE]>+ 1))[:self.SLICE_SIZE]
27        return f'/------------\\\n|{filling_content}|\n|{filling_content28        return f'/------------\\\n|{stuff}|\n|{stuff}|\n|{stuff}|\n\\---
>}|\n|{filling_content}|\n\\------------/'>---------/'
2829
n29    def _generate_partial_bun(self, bun_length):n30    def _create_partial_sausage(self, stuffing_length):
30        filling_content = (self.filling * (bun_length // len(self.fillin31        stuff = (self.stuffing * (stuffing_length // len(self.stuffing) 
>g) + 1))[:bun_length]>+ 1))[:stuffing_length]
31        return f'/{'-' * bun_length}|\n|{filling_content}|\n|{filling_co32        return f'/{'-' * stuffing_length}|\n|{stuff}|\n|{stuff}|\n|{stuf
>ntent}|\n|{filling_content}|\n\\{'-' * bun_length}|'>f}|\n\\{'-' * stuffing_length}|'
3233
n33    def _combine_buns(self, buns):n34    def _combine_sausages(self, sausages):
34        rows = [bun.split('\n') for bun in buns]35        rows = [sausage.split('\n') for sausage in sausages]
35        combined_rows = [''.join(row) for row in zip(*rows)]36        combined = [''.join(row) for row in zip(*rows)]
36        return '\n'.join(combined_rows)37        return '\n'.join(combined)
3738
38    def __abs__(self):39    def __abs__(self):
n39        return abs(self.quantity)n40        return abs(self.volume)
4041
41    def __add__(self, other):42    def __add__(self, other):
n42        total_size = self.quantity + other.quantityn43        new_volume = self.volume + other.volume
43        return Sausage(self.filling, max(total_size, Fraction(0)))44        return Sausage(self.stuffing, max(new_volume, Fraction(0)))
4445
45    def __sub__(self, other):46    def __sub__(self, other):
n46        reduced_size = self.quantity - other.quantityn47        new_volume = self.volume - other.volume
47        return Sausage(self.filling, max(reduced_size, Fraction(0)))48        return Sausage(self.stuffing, max(new_volume, Fraction(0)))
4849
n49    def __mul__(self, multiplier):n50    def __mul__(self, factor):
50        if isinstance(multiplier, int) and multiplier >= 0:51        if isinstance(factor, int) and factor >= 0:
51            return Sausage(self.filling, self.quantity * multiplier)52            return Sausage(self.stuffing, self.volume * factor)
52        raise ValueError('Multiplier must be a non-negative integer.')53        raise ValueError('Multiplication factor must be a non-negative i
 >nteger.')
5354
n54    def __rmul__(self, multiplier):n55    def __rmul__(self, factor):
55        return self.__mul__(multiplier)56        return self.__mul__(factor)
5657
57    def __truediv__(self, divisor):58    def __truediv__(self, divisor):
58        if isinstance(divisor, int) and divisor > 0:59        if isinstance(divisor, int) and divisor > 0:
n59            return Sausage(self.filling, self.quantity / divisor)n60            return Sausage(self.stuffing, self.volume / divisor)
60        raise ValueError('Divisor must be a positive integer.')61        raise ValueError('Division divisor must be a positive integer.')
6162
62    def __bool__(self):63    def __bool__(self):
t63        return self.quantity != 0t64        return self.volume != 0
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op