Created
October 21, 2016 15:44
-
-
Save AndyNovo/fdd20cb058299020aa00b8df87ae3e89 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| class VariableGenerator(object): | |
| def __init__(self, prefix): | |
| self.__prefix = prefix | |
| @cached_method | |
| def __getitem__(self, key): | |
| return SR.var("%s%s"%(self.__prefix,key)) | |
| a=VariableGenerator('a') | |
| answers={} | |
| def aa(n): | |
| if n in answers: | |
| return answers[n] | |
| if n <= 30: | |
| answers[n] = a[n] | |
| return a[n] | |
| elif n <= 33: | |
| answers[n] = aa(n-31) | |
| return answers[n] | |
| else: | |
| answers[n] = aa(n-31) + aa(n-3) | |
| return answers[n] | |
| R=IntegerModRing(2**32) | |
| def eq2vec(eq): | |
| return [eq.coefficient(a[i]) for i in range(31)] | |
| V = [eq2vec(aa(344 + i)) for i in range(31)] | |
| M = Matrix(R, V) | |
| IM = M.inverse() | |
| IM[0] | |
| map(lambda x: Integer(x) if x < 2**31 else Integer(x) - 2**32, IM[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment