Solve 2020 day 13 CRT jojo

This commit is contained in:
2024-09-14 10:41:22 -04:00
parent 4a72eeb348
commit 6e588bb928
3 changed files with 56 additions and 1 deletions

15
lib.py
View File

@@ -280,3 +280,18 @@ def get_data(filename):
assert os.path.isfile(txt_file), "Could not download AoC file"
with open(txt_file) as f:
return f.read()
def mod_inverse(a, m):
def egcd(a, b):
if a == 0:
return b, 0, 1
else:
g, y, x = egcd(b % a, a)
return g, x - (b // a) * y, y
g, x, _ = egcd(a, m)
if g != 1:
raise Exception('Modular inverse does not exist')
else:
return x % m