def __add__(self, other): num1 = exploderise(self.num) num2 = exploderise(other.num) combination = num1 + num2 reversed_sorted_combination = sort_num(combination, rev=False) combined = combine(reversed_sorted_combination) combined[::-1] return RomanNumeral(compressurise(combined))
def __sub__(self, other): num1 = exploderise(self.num) num2 = exploderise(other.num) c = Counter(num1) c.subtract(Counter(num2)) letters = sorted(values.keys(), key=sorter) for i, l in enumerate(letters): if c[l] < 0: if l == 'V': c.subtract(Counter({l:-2, letters[i+1]:1})) else: c.subtract(Counter({l:-5, letters[i+1]:1})) expanded_number = sort_num(c.elements()) corrected_number = compressurise(combine(expanded_number)) return RomanNumeral(corrected_number)