Skip to content

Instantly share code, notes, and snippets.

@kbob
Created December 23, 2012 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kbob/4364245 to your computer and use it in GitHub Desktop.
Save kbob/4364245 to your computer and use it in GitHub Desktop.
Find Ramanujan's number.
#!/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