Skip to content

Instantly share code, notes, and snippets.

@LoLei
Created April 21, 2015 20:27
Show Gist options
  • Save LoLei/1de25cf9b8513832c39b to your computer and use it in GitHub Desktop.
Save LoLei/1de25cf9b8513832c39b to your computer and use it in GitHub Desktop.
Chinese Remainder Theorem
#!/usr/bin/python3
# coding=utf-8
"""
Diskrete Mathematik ÜB 14 Beispiel 18
Chinesischer Restsatz
"""
__author__ = "Lorenz Leitner"
__updated__ = "04-21-2015"
def product(modules):
p = 1
for i in modules:
p *= i
return p
modules = (5, 7, 8, 11)
m = product(modules)
for x in range(0, m):
if (x % 5 == 1 % 5)\
and (x % 7 == 2 % 7)\
and (x % 8 == 0 % 8)\
and (x % 11 == 3 % 11):
break
print("x =", x, "+ k *", m)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment