Created
October 2, 2014 11:38
-
-
Save mpetyx/695c70be98a46138707c to your computer and use it in GitHub Desktop.
Hardy Ramanujan Number in Python. A sample implementation with no optimizations
This file contains 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
__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 | |
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
Can you provide any quicker method