Last active
April 19, 2022 16:24
-
-
Save corehello/c173ff5b3be5e79642234a7b57c4a239 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from operator import mul, add | |
from functools import reduce | |
def chinese_remainder_theorem(tuple): | |
transpose = list(zip(*tuple)) | |
product = reduce(mul, transpose[0]) | |
min_result = reduce(add, [ | |
j * l *(l%i) for i,j in tuple for l in [reduce(mul, [k for k in transpose[0] if k != i])] | |
]) % product | |
print("The value is: %s + n * %s which n = 0..inf" % (min_result, product)) | |
return min_result, product |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cool~