Example #1
0
def fund(n):
    lower, upper = bounds(n)
    p = 0
    for b in range(lower, upper+1):
        r = n - b
        for seq in mtools.comb(range(1,n+1), r):
            a = mtools.mul(seq)
            p += a
    return mtools.fac(n+1)/p
Example #2
0
def sum_c(n):
    s = 0
    l = range(n)
    for i in range(2, n-1):
        combs = mtools.comb(l, i)
        combs2 = [c for c in combs]
        #print combs2
        s += to_compare(combs2)
    return s
Example #3
0
def solve():
    l = [str(x) for x in mtools.sieve_primes(1000000)]
    for i in range(5,8):
        dls = mtools.comb(range(i-1), 3)
        for l2 in dls:
            l2.sort()
            print i, l2
            n, p = detect(i, l, l2)
            if n == 8:
                return p
Example #4
0
def select_p(p, c, n):
    l = []
    for i in range(len(p)):
        if c[i] > n:
            l = l + [i]*n
        elif c[i] > 0:
            l = l + [i]*c[i]
    lc = mtools.comb(l, n)
    lu = unique_list(lc)
    lu.sort(cmp=lambda x,y: cmp(mul_p(p, x), mul_p(p, y)))
    return lu
Example #5
0
def extend_list(l, sz, lim):
    if len(l) == sz:
        return [l]
    s = set(range(lim)) - set(l)
    n = sz - len(l)
    ls = mtools.comb(list(s), n)
    lr = []
    for le in ls:
        lt = l + le
        lt.sort()
        lr.append(list(lt))
    return lr
Example #6
0
def solve():
    m = 0
    le = mtools.comb(range(1,10), 4)
    for es in le:
        l = target_numbers(es)
        t = consecutive_numbers(l)
        #print es, t
        if t > m:
            m = t
            lr = list(es)
            lr.sort()
            print lr, t
    return lr
Example #7
0
def is_special_set(l):
    l.sort()
    tab = {}
    i = 1
    while i < len(l):
        m = get_max(l, i) 
        for subs in mtools.comb(l, i):
            s = sum(subs)
            if s <= m:
                return False
            try:
                if tab[s]:
                    return False
            except KeyError:
                tab[s] = i
        i += 1
    return True