module.py

mail@pastecode.io avatar
unknown
plain_text
a year ago
978 B
6
Indexable
Never
class LongInt:
    def __init__(self, number_str):
        self.numbers = self.parse_number_str(number_str)

    def parse_number_str(self, number_str):
        if len(number_str) < 20:
            number_str = '0' * (20 - len(number_str)) + number_str
        return [int(digit) for digit in number_str]

    def add_num(self, other):
        result = []
        carry_bit = False

        for i in range(19, -1, -1):
            digit_sum = self.numbers[i] + other.numbers[i]

            if carry_bit:
                digit_sum += 1

            if digit_sum > 9:
                carry_bit = True
                digit_sum %= 10
            else:
                carry_bit = False

            result.insert(0, digit_sum)

        return LongInt(''.join(map(str, result)))

    def print_longint(self):
        digits = ''.join(str(digit) for digit in self.numbers)
        for i in range(0, len(digits), 10):
            print(digits[i:i+10])