Last active
September 13, 2018 08:12
-
-
Save aib/103ab9529ae8790cc8ffffd525a1935c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import functools as ft | |
import itertools as it | |
import operator as op | |
def generate_factors(b, n, smallest_number=1): | |
if n == 1: | |
yield [b] | |
else: | |
for i in range(smallest_number, b // 2 + 1): | |
for s in generate_factors(b-i, n-1, i): | |
yield [i] + s | |
def duplicate_products(cs): | |
seen = set() | |
dups = set() | |
for c in cs: | |
product = ft.reduce(op.mul, c, 1) | |
if product in seen: | |
dups.add(product) | |
seen.add(product) | |
return dups | |
def factors_with_sum(b): | |
return map(lambda n: (n, list(generate_factors(b, n))), range(1, b + 1)) | |
def analyze_duplicates(b): | |
dup_coords = set() | |
for n, cs in factors_with_sum(b): | |
dups = duplicate_products(cs) | |
for a in dups: | |
dup_coords.add((b, n, a)) | |
return dup_coords | |
for b in [12, 13, 14]: | |
print(b, analyze_duplicates(b)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment