def distinct_primes(num): """ The first `num` consecutive numbers to have `num` distinct prime factors """ distinct_factors = [] i = 0 while len(distinct_factors) != num ** 2: i += 1 factors = [prime_factors(x) for x in range(i, i + num)] distinct_factors = {x for factor in factors for x in factor} print i
def test_prime_factorisation(self): """unittest prime_factorisation.prime_factors()""" self.assertEqual(prime_factorisation.prime_factors(999), [3, 3, 3, 37, 1])
""" combs = [] for iii in xrange(1, len(lst)+1): els = [list(x) for x in itertools.combinations(lst, iii)] combs.extend(els) return combs def generate_triangle_numbers(): """ return triangle numbers """ iii = 0 tri = 0 while True: iii += 1 tri += iii yield tri TRIANGLE_NUMBER_GENERATOR = generate_triangle_numbers() NUMBER_OF_FACTORS = 0 while NUMBER_OF_FACTORS < 500: TRIANGLE_NUMBER = TRIANGLE_NUMBER_GENERATOR.next() FACTORS = prime_factors(TRIANGLE_NUMBER) COMBINTIONS = get_combintions(FACTORS) COMBINTIONS = [np.prod(i) for i in COMBINTIONS] NUMBER_OF_FACTORS = len(set(COMBINTIONS)) print TRIANGLE_NUMBER