Пример #1
0
def get_number_of_divisors(max_divisor):

    total = 0
    gen = gmath.gen_triangle_numbers()

    while total < max_divisor:
        
        # get prime factors of next triangle number
        tri_num = gen.next()
        prime_factors = g.get_prime_factors(tri_num)

        # If n = a^c * b^d where a and b are n's prime divisors, repeated c and
        # d times respectively, then n's number of divisors is (c + 1) * (d + 1)
        counter = collections.Counter(prime_factors)
        number_of_each_divisor = counter.values()
        number_of_each_divisor = [i+1 for i in number_of_each_divisor]
        total = reduce(operator.mul, number_of_each_divisor, 1)

    return tri_num
Пример #2
0
def main():

    path = os.path.normpath(os.path.dirname(__file__) +
                            '../../txt/pe42_words.txt')
    with open(path) as f:
        word_list = f.read().split(',')
        word_list = [word.strip('"') for word in word_list]
    f.close()

    # generate hash table of triangle numbers
    tri_hash = {}
    gen = gmath.gen_triangle_numbers()
    for x in range(50):
        n = gen.next()
        tri_hash[n] = [n]

    result = 0
    for word in word_list:
        if tri_hash.get(gmath.get_alphabet_value_word(word)) != None:
            result += 1
    return result