Last active
January 5, 2018 15:30
-
-
Save ultimatecoder/ae35b59aac23832cf29efc74af8ff2f6 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
from collections import defaultdict | |
def product(a, b, c, d): | |
return [(a, b, c, d), (a, b, d, c), (b, a, c, d), (b, a, d, c)] | |
def count_hack(n): | |
results = [] | |
sums = defaultdict(set) | |
for a in range(1, n): | |
results.append((a, a, a, a)) | |
for b in range(a+1, n+1): | |
results.extend(product(a, b, a, b)) | |
sum_ = a ** 3 + b ** 3 | |
for values in sums[sum_]: | |
results += product(a, b, *values) + product(*values, a, b) | |
sums[sum_].add((a, b)) | |
results.append((b, b, b, b)) | |
return results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment