-
-
Save VHarisop/09c2321c7d7ed8339540 to your computer and use it in GitHub Desktop.
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__ = 'VHarisop' | |
''' original idea from mpetyx <github.com/mpetyx> | |
Generates Hardy-Ramanujan Numbers up to 250000 in under 1 sec. | |
''' | |
import sys | |
rng = int(sys.argv[1]) | |
hrs = [0] * (2 * rng ** 3 + 1) | |
for x in range(1, rng): | |
for y in range(x, rng): | |
hrs[x**3 + y**3] += 1 | |
for i in range(0, 2 * rng**3 + 1): | |
if hrs[i] > 1: | |
print i | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Initially (as can be seen in the revision history), I was using a class with the sum as key, and a set to contain the possible number tuples that generate it, with the intention of putting those in a, indeed sparse, array. But I was exploring what then became this version so I never tried out your way, which is pretty cool.
I am pretty familiar with B/B+ trees (and SWIG as well!), so if I find some spare time I might look into this solution. I don't think there is a mathematical property that holds for these numbers, but - concerning your method - there might be a way to generate them (at least) in a partially sorted order to make the most out of Python's Timsort.