Created
December 23, 2012 16:43
-
-
Save kbob/4364245 to your computer and use it in GitHub Desktop.
Find Ramanujan's number.
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
#!/usr/bin/python | |
from itertools import count | |
def ramanujan_number(): | |
cubes = (i**3 for i in count(1)) | |
smaller_cubes = [] | |
sums = {} | |
for n in cubes: | |
for m in smaller_cubes: | |
sc = n + m | |
if sc in sums: | |
n1, m1 = sums[sc] | |
print '%d + %d = %d + %d = %d' % (n, m, n1, m1, sc) | |
return sc | |
sums[n + m] = (n, m) | |
smaller_cubes.append(n) | |
if __name__ == '__main__': | |
ramanujan_number() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment