class Modular:
"""
Performs modular arithmetic with the given value and modulus.
"""
value: float
modulus: float
def __init__(self, value: float, modulus: float) -> None:
self.value = value
self.modulus = modulus
def __add__(self, other):
assert self.modulus == other.modulus, "Moduli must be the same"
value = self.value + other.value
return Modular(value % self.modulus, self.modulus)
def __sub__(self, other):
assert self.modulus == other.modulus, "Moduli must be the same"
value = self.value - other.value
return Modular(value % self.modulus, self.modulus)
def __repr__(self) -> str:
return f"Modular({self.value}, {self.modulus})"
# self.value%self.modulus
x = Modular(23, 24)
y = Modular(2, 24)
print(x + y)