当前位置: 首页>>代码示例>>Python>>正文


Python decorators.euler_timer函数代码示例

本文整理汇总了Python中python.decorators.euler_timer函数的典型用法代码示例。如果您正苦于以下问题:Python euler_timer函数的具体用法?Python euler_timer怎么用?Python euler_timer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了euler_timer函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: prime_concat_partners

def prime_concat_partners(list_, primes, failure_point):
    result = {}

    length = len(list_)
    for first in range(length - 1):
        n1 = list_[first]
        for second in range(first + 1, length):
            n2 = list_[second]
            cand1 = int(str(n1) + str(n2))
            cand2 = int(str(n2) + str(n1))
            if is_prime(cand1, primes=primes, failure_point=failure_point):
                if is_prime(cand2, primes=primes, failure_point=failure_point):
                # sets value to [] if not set, returns value at key
                result.setdefault(n1, []).append(n2)
                result.setdefault(n2, []).append(n1)
    return result

def possible_pairings(partner_hash, length):
    # length = 1
    result = [[key] for key in partner_hash]
    for size in range(2, length + 1):
        next_iteration = []
        for subset in result:
            possible_additions = partner_hash[subset[0]]
            for val in subset:
                possible_additions = [entry for entry in possible_additions
                                      if entry in partner_hash[val]]
            next_iteration.extend([subset[:] + [candidate]
                                   for candidate in possible_additions])
        result = next_iteration
    return result


def main(verbose=False):
    MAX_n = 10**4
    PRIMES = sieve(MAX_n)
    partner_hash = prime_concat_partners(PRIMES, PRIMES, MAX_n**2)
    valid = possible_pairings(partner_hash, 5)

    min_sum = 10**10
    min_set = None
    for subset in valid:
        if sum(subset) < min_sum:
            min_sum = sum(subset)
            min_set = subset

    min_set = [str(prime) for prime in sorted(min_set)]
    if verbose:
        return '%s.\nThis is obtained with the primes %s.' % (
            min_sum, ', '.join(min_set))
    else:
        return min_sum

if __name__ == '__main__':
    print euler_timer(60)(main)(verbose=True)
开发者ID:mireq,项目名称:project-euler,代码行数:55,代码来源:no060.py

示例2: range

    return [x ** 3 for x in range(m, M + 1)]


def has_k_perms(digits, k, cubes):
    sorted_cubes = {}
    for cube in cubes:
        sorted_digs = ''.join(sorted(str(cube)))
        # sets value to [] if not set, returns value at key
        sorted_cubes.setdefault(sorted_digs, []).append(cube)

    possible_matches = [value for value in sorted_cubes.values()
                        if len(value) == 5]

    possible_matches.sort(key=lambda list_: min(list_))
    if possible_matches:
        return min(possible_matches[0])
    else:
        return -1


def main(verbose=False):
    digits = len(str(41063625))
    cubes = all_cubes(digits)
    while has_k_perms(digits, 5, cubes) == -1:
        digits += 1
        cubes = all_cubes(digits)
    return has_k_perms(digits, 5, cubes)

if __name__ == '__main__':
    print euler_timer(62)(main)(verbose=True)
开发者ID:dhermes,项目名称:project-euler,代码行数:30,代码来源:no062.py


注:本文中的python.decorators.euler_timer函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。