Skip to content

Instantly share code, notes, and snippets.

@ultimatecoder
Last active January 5, 2018 15:30
Show Gist options
  • Save ultimatecoder/ae35b59aac23832cf29efc74af8ff2f6 to your computer and use it in GitHub Desktop.
Save ultimatecoder/ae35b59aac23832cf29efc74af8ff2f6 to your computer and use it in GitHub Desktop.
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