Skip to content

Instantly share code, notes, and snippets.

@mpetyx
Created October 2, 2014 11:38
Show Gist options
  • Save mpetyx/695c70be98a46138707c to your computer and use it in GitHub Desktop.
Save mpetyx/695c70be98a46138707c to your computer and use it in GitHub Desktop.
Hardy Ramanujan Number in Python. A sample implementation with no optimizations
__author__ = 'mpetyx'
for x in range(1, 2000):
for y in range(1, 2000):
for z in range(1, 2000):
for g in range(1, 2000):
if g * g * g + z * z * z == x * x * x + y * y * y:
if (g == z) or (g == y) or (g == x) or (z == y) or (z == x) or (y == x):
continue
else:
print "x=", x
print "y=", y
print "z=", z
print "g=", g
print g * g * g + z * z * z
print
print
@jitendra424
Copy link

Can you provide any quicker method

@SneakyBerry
Copy link

nums = {}
max_n = 100

for x in range(1, max_n + 1):
    for y in range(x, max_n + 1):
        key = x ** 3 + y ** 3
        entry = nums.setdefault(key, [])
        entry.append((x, y))
        if len(entry) > 1:
            print(key, entry)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment