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


Python Utils.exec_time方法代码示例

本文整理汇总了Python中utils.Utils.exec_time方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.exec_time方法的具体用法?Python Utils.exec_time怎么用?Python Utils.exec_time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utils.Utils的用法示例。


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

示例1: range

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import exec_time [as 别名]
        [447, 283, 463, 29, 23, 487, 463, 993, 119, 883, 327, 493, 423, 159, 743],
        [217, 623, 3, 399, 853, 407, 103, 983, 89, 463, 290, 516, 212, 462, 350],
        [960, 376, 682, 962, 300, 780, 486, 502, 912, 800, 250, 346, 172, 812, 350],
        [870, 456, 192, 162, 593, 473, 915, 45, 989, 873, 823, 965, 425, 329, 803],
        [973, 965, 905, 919, 133, 673, 665, 235, 509, 613, 673, 815, 165, 992, 326],
        [322, 148, 972, 962, 286, 255, 941, 541, 265, 323, 925, 281, 601, 95, 973],
        [445, 721, 11, 525, 473, 65, 511, 164, 138, 672, 18, 428, 154, 448, 848],
        [414, 456, 310, 312, 798, 104, 566, 520, 302, 248, 694, 976, 430, 392, 198],
        [184, 829, 373, 181, 631, 101, 969, 613, 840, 740, 778, 458, 284, 760, 390],
        [821, 461, 843, 513, 17, 901, 711, 993, 293, 157, 274, 94, 192, 156, 574],
        [ 34, 124, 4, 878, 450, 476, 712, 914, 838, 669, 875, 299, 823, 329, 699],
        [815, 559, 813, 459, 522, 788, 168, 586, 966, 232, 308, 833, 251, 631, 107],
        [813, 883, 451, 509, 615, 77, 281, 613, 459, 205, 380, 274, 302, 35, 805]]

    for r in range(len(A)):
        for c in range(len(A[0])):
            A[r][c] *= -1

    from munkres import Munkres, print_matrix

    m = Munkres()
    indexes = m.compute(A)
    total = 0
    for row, column in indexes:
        value = A[row][column]
        total += value
        #print '(%d, %d) -> %d' % (row, column, value)
    print -total

u.exec_time(p345)
开发者ID:,项目名称:,代码行数:32,代码来源:

示例2: Utils

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import exec_time [as 别名]
#
#Given that F_k is the first Fibonacci number for which the
#first nine digits AND the last nine digits are 1-9
#pandigital, find k.

from utils import Utils
from math import sqrt
from decimal import Decimal

u = Utils()

def is_pandigital(n):
    return ''.join(sorted(str(n))) == '123456789'

def p104():
    phi = (1 + sqrt(5)) / 2.
    c = sqrt(5)
    i = 2
    f = Decimal((phi ** 2) / c)
    m = str(f)[:10].replace('.', '')
    a, b = 1, 1
    while not (is_pandigital(m) and is_pandigital(a)):
        a, b = (a + b) % (10 ** 9), a % (10 ** 9)
        f *= Decimal(phi)
        m = str(f)[:10].replace('.', '')
        i += 1
    print i

u.exec_time(p104)

开发者ID:,项目名称:,代码行数:31,代码来源:

示例3: when

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import exec_time [as 别名]
#Let p_n be the nth prime: 2, 3, 5, 7, 11, ..., and let r
#be the remainder when (p_n − 1)^n + (p_n + 1)^n is divided
#by p_n^2.
#
#For example, when n = 3, p_3 = 5, and 4^3 + 6^3 = 280
#≡ 5 mod 25.
#
#The least value of n for which the remainder first exceeds
#10^9 is 7037.
#
#Find the least value of n for which the remainder first
#exceeds 10^10.

from utils import Utils

u = Utils()

p = u.sieve(4 * (10 ** 5))

def p123():
    i = 0
    a = 0
    while a < 10 ** 10 and i < len(p):
        i += 1
        a = (2 * p[i] * (i + 1)) % (p[i] ** 2)
    #sum 2 because i is the index of the number just below
    #10 ** 10, and array indices start by 0:
    print i + 2

u.exec_time(p123)
开发者ID:,项目名称:,代码行数:32,代码来源:

示例4: count_solutions

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import exec_time [as 别名]
#
#{20,48,52}, {24,45,51}, {30,40,50}
#
#For which value of p <= 1000, is the number of solutions
#maximised?

from utils import Utils

def count_solutions(p):
    total = 0
    for a in xrange(1, p):
        for b in range(a, p):
            c = p - a - b
            if 0 < a <= b < c:
                if c ** 2 == a ** 2 + b ** 2:
                    total += 1
    return total

def p39():
    max_count = -1
    perimeter = -1
    for p in range(4, 1001, 2):
        m = count_solutions(p)
        if m > max_count:
            max_count = m
            perimeter = p
    print max_count, perimeter

u = Utils()
u.exec_time(p39)
开发者ID:,项目名称:,代码行数:32,代码来源:

示例5: map

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import exec_time [as 别名]
        c = str_num[-1]
        str_num = str_num[:-1]
        c += str_num
        str_num = c
        lista.append(c)
        i += 1
    return map(int, lista)

def all_in(l1, l2, u):
    for n in l1:
        if u.chop(n, l2) == -1:
            return False
    return True

def p35():
    u = Utils()
    sieve = u.sieve(10 ** 6)
    count = 0
    for prime in sieve:
        s = str(prime)
        l = cyclic_shifts_of(s)
        if all_in(l, sieve, u):
            count += 1
    return count

def exec_():
    print p35()

u = Utils()
u.exec_time(exec_)
开发者ID:,项目名称:,代码行数:32,代码来源:

示例6: p71

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import exec_time [as 别名]
#
#If we list the set of reduced proper fractions for d <= 8
#in ascending order of size, we get:
#
#1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2, 4/7,
#3/5, 5/8, 2/3, 5/7, 3/4, 4/5, 5/6, 6/7, 7/8.
#
#It can be seen that 2/5 is the fraction immediately to the
#left of 3/7. 
#
#By listing the set of reduced proper fractions for
#d <= 1,000,000 in ascending order of size, find the
#numerator of the fraction immediately to the left of 3/7.

from fractions import gcd
from utils import Utils

#This just does a brute-force search; fortunately enough,
#it finds the correct solution within a proper time limit.
#This one needs to be revised to remember how did I do it.
def p71():
    min_a, min_b = 2, 5
    for k in xrange(10 ** 6):
        b, a = 5 + 7 * k, 2 + 3 * k
        if min_a * b < min_b * a and 7 * a < 3 * b and b < 10 ** 6:
            min_a, min_b = a, b
    print(min_a, min_b, gcd(min_a, min_b))

u = Utils()
u.exec_time(p71)
开发者ID:,项目名称:,代码行数:32,代码来源:

示例7: is_right_truncatable

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import exec_time [as 别名]
def is_right_truncatable(p, u, sieve):
    while p > 10:
        p /= 10
        if u.chop(p, sieve) == -1:
            return False
    return True

def is_left_truncatable(p, u, sieve):
    p_str = str(p)
    while len(p_str) > 1:
        p_str = p_str[1:]
        if u.chop(int(p_str), sieve) == -1:
            return False
    return True

def p37():
    u = Utils()
    primes = u.sieve(10 ** 6)
    total = 0
    for p in primes:
        a = is_right_truncatable(p, u, primes)
        b = is_left_truncatable(p, u, primes)
        if a and b:
            total += p
    #we have to ignore 2, 3, 5, and 7, which sum up to 17:
    print total - 17

u = Utils()
u.exec_time(p37)
开发者ID:,项目名称:,代码行数:31,代码来源:

示例8: bisect_left

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import exec_time [as 别名]
    # insert, so check that first.
    # Else, if the item is in the list then it has to be at
    # index bisect_left(lst, item).
    return (item <= lst[-1]) and \
        (lst[bisect_left(lst, item)] == item)

import time

def p50():
    #initial values:
    k = 2
    p1 = u.sieve(10 ** 6)
    pl = k_consecutive_prime_sums(p1, k, 10 ** 6)
    m = len(pl)
    max_k = -1
    p_k = 0

    #creating the k-prime sums given the (k - 1)-prime sums:
    while m > 0:
        m = len(pl) - 1
        pl = [pl[i] + p1[i + k] for i in range(m)
            if pl[i] + p1[i + k] < 10 ** 6]
        k += 1
        for prime in pl:
            if bi_contains(p1, prime) and k > max_k:
                max_k = k
                p_k = prime
    print max_k, p_k

u.exec_time(p50)
开发者ID:,项目名称:,代码行数:32,代码来源:

示例9: len

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import exec_time [as 别名]
                    continue
                while n_ % p == 0:
                    n_ /= p
                if n_ < len(l):
                    l.append(p * l[int(n_)])
                    break
        i += 1
    return l

def p127(max_c, exp):
    u = Utils()
    primes = u.sieve(max_c)
    radicals = rad(int(max_c), primes)
    possible_ys = [i for i in range(1, max_c) if radicals[i] <= int(max_c ** exp)]
    possible_rads = [radicals[i] for i in possible_ys]
    print("len(radicals):", len(radicals))
    print("len(possible_ys):", len(possible_ys))
    print(possible_ys)
    print(possible_rads)
    total = 0
    for a in possible_ys:
        for b in possible_ys:
            c = a + b
            if a < b and c < max_c and hit(a, b, c, radicals):
                print(a,b,c)
                total += c
    print(total)

u = Utils()
u.exec_time(lambda: p127(120000, 0.8))
开发者ID:,项目名称:,代码行数:32,代码来源:

示例10: atan

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import exec_time [as 别名]
    #angle between these lines:
    theta0 = atan((mr[1] - mt[1]) / (1 + (mr[1] * mt[1])))
    #print 'theta = {0} rad'.format(theta0)

    #get reflected ray equation:
    mr_, br_ = u.rotate_line(mt, bt, pt, -theta0)
    #print mr_, br_

    #Solve equation given its coefficients. This solves
    #for the parameter t!!!
    a = (4 * mr_[0] * mr_[0]) + (mr_[1] * mr_[1])
    b = (8 * mr_[0] * br_[0]) + (2 * mr_[1] * br_[1])
    c = (4 * br_[0] * br_[0]) + (br_[1] * br_[1]) - 100
    t = u.solve_quadratic(a, b, c)

    #get right coordinate:
    ps = [u.get_point(mr_, br_, t[0]),
          u.get_point(mr_, br_, t[1])]
    return ps[1 if close_enough(ps[0], pt) else 0]

def p144():
    i = 0
    p, pt = [0.0, 10.1], [1.4, -9.6]
    while  (-0.01 > pt[0] or pt[0] > 0.01) or pt[1] < 0:
        p, pt = pt, next_point(p, pt)
        i += 1
    print i

u.exec_time(p144)
开发者ID:,项目名称:,代码行数:31,代码来源:

示例11: p

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import exec_time [as 别名]
#Find the least value of n for which p(n) is divisible by
#one million.

from utils import Utils

u = Utils()

p = [1, 1]

def part2(n):
    sum, k, a, b, sgn = 0, 4, 2, 1, 1
    while n >= a:
        sum += sgn * (p[n - a] + p[n - b])
        a += k + 1
        b += k
        sgn *= -1
        k += 3
    if n >= b:
        sum += sgn * p[n - b]
    return sum % (10 ** 6)

def p78():
    i = 1
    while p[i] != 0:
        i += 1
        d = part2(i)
        p.append(d)
    print i

u.exec_time(p78)
开发者ID:,项目名称:,代码行数:32,代码来源:

示例12: x

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import exec_time [as 别名]
#There are exactly ten ways of selecting three from five,
#12345:
#
#123, 124, 125, 134, 135, 145, 234, 235, 245, and 345.
#
#In combinatorics, we use the notation, 5C3 = 10.
#
#In general,
#
#nCr= n!/(r!(n−r)!), where r <= n, n! =
#n x (n−1) x ... x 3 x 2 x 1, and 0! = 1. It is not until
#n = 23, that a value exceeds one-million: 23C10 = 1144066.
#
#How many, not necessarily distinct, values of nCr, for
#1 <= n <= 100, are greater than one-million?

from utils import Utils

def p53():
    u = Utils()
    mat, val = u.binom(100, 100)
    total = 0
    for r in range(len(mat)):
        for c in range(len(mat[0])):
            if mat[r][c] > 10 ** 6:
                total += 1
    print total

u = Utils()
u.exec_time(p53)
开发者ID:,项目名称:,代码行数:32,代码来源:

示例13: n

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import exec_time [as 别名]
#Pentagonal Pn = n(3n - 1)/2: 1, 5, 12, 22, 35, ...
#Hexagonal Hn = n(2n - 1): 1, 6, 15, 28, 45, ...
#
#It can be verified that T_285 = P_165 = H_143 = 40755.
#
#Find the next triangle number that is also pentagonal and
#hexagonal.

from utils import Utils

def p45():
    u = Utils()
    a, b = 1, 1
    i = 0
    h_, k_, r_ = 0, 0, 0
    while i < 3:
        a, b = 2 * a + 3 * b, a + 2 * b
        if a % 6 == 5 and b % 2 == 1:
            #triangular:
            h_ = (b - 1) / 2
            #pentagonal:
            k_ = (a + 1) / 6
            if h_ % 2 == 1:
                #hexagonal:
                r_ = (h_ + 1) / 2
                i += 1
    print u.t(h_)

u = Utils()
u.exec_time(p45)
开发者ID:,项目名称:,代码行数:32,代码来源:

示例14: googol

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import exec_time [as 别名]
#A googol (10^100) is a massive number: one followed by
#one-hundred zeros; 100^100 is almost unimaginably large:
#one followed by two-hundred zeros. Despite their size, the
#sum of the digits in each number is only 1.
#
#Considering natural numbers of the form, a^b, where
#a, b < 100, what is the maximum digital sum?

from utils import Utils

def digit_sum(a, b):
    m = a ** b
    s = str(m)
    total = reduce(lambda x, y: x + y, map(int, s))
    return total

def p56():
    max = -1
    max_a, max_b = 0, 0
    for a in range(100):
        for b in range(100):
            m = digit_sum(a, b)
            if m > max:
                max = m
                max_a = a
                max_b = b
    print m, max_a, max_b

u = Utils()
u.exec_time(p56)
开发者ID:,项目名称:,代码行数:32,代码来源:

示例15: Y

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import exec_time [as 别名]
#
#X(-175,41), Y(-421,-714), Z(574,-645)
#
#It can be verified that triangle ABC contains the origin,
#whereas triangle XYZ does not.
#
#Using triangles.txt (right click and 'Save Link/Target
#As...'), a 27K text file containing the co-ordinates of one
#thousand "random" triangles, find the number of triangles
#for which the interior contains the origin.
#
#NOTE: The first two examples in the file represent the
#triangles in the example given above.

from utils import Utils

u = Utils()

def p102():
    total = 0
    P = [0, 0]
    triangles = []

    for line in open('../data/p102_triangles.txt'):
        a1, a2, b1, b2, c1, c2 = map(int, line.split(','))
        total += u.in_triangle(P,
            [(a1, a2), (b1, b2), (c1, c2)])
    print total

u.exec_time(p102)
开发者ID:,项目名称:,代码行数:32,代码来源:


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