1. 53.The arrangement of the god

    # find if n*(n-1)/2 can be separated into two adjacent numbers
    def adjacent(num):
        a=round(num**(1/2.0),0)
        if a*(a+1)==num:
            return True
    
    god_num = 0
    for n in range(2,N+1):
        if adjacent(n*(n-1)/2):
            god_num+=1
            print n
    print(god_num ...
    read more
  2. 52.Factor sum of squares

    # -*- coding: utf-8 -*-
    
    # s = 0
    # for i in range(1,N+1):
    #   s = s + i**2*(N//i)    # step 1
    # print (s)
    
    # N = 16
    # L1 = list(range(1,N+1))
    # L2 = [N//i for i in L1]    # step 2 [16, 8, 5, 4, 3, 2, 2, 2, 1, 1, 1, 1 ...
    read more
  3. 48.Weight problems 2

    w=[2,5,11]
    n=9
    L=len(w)
    s=[-1 for i in range(n+1)]
    s[0]=0
    print s
    for i in range(L):
        for j in range(1,n+1):
            if j-w[i]>=0 and s[j-w[i]]!=-1: # n>=each weight, their difference ...
    read more
  4. 47.Yang hui triangle

    n=6
    l0 = [1]
    l1 = [1,1]
    print " ".join([str(x) for x in l0])
    print " ".join([str(x) for x in l1])
    for i in range(2, n):
        lnew = [1]
        for j in range(1, len(l1)):
            lnew.append(l1[j-1]+l1[j])
        lnew.append(1)
        l1 = lnew ...
    read more
  5. 46.Take stones game

    # (1, 2) (3, 5) (4, 7) (6, 10) (8, 13) (9, 15) (11, 18) (12, 20) (14, 23) (16, 26) (17, 28) (19, 31)...
    # a/b = (sqrt(5) - 1)/2 = 0.618
    
    a=8
    b=13
    if a > b:
        a, b = b, a
    k = b - a
    c = k * 1.6180339887498949 ...
    read more
  6. 45.Weight problems

    w=[1,3]
    n=[2,1]
    W = [0]
    L = [0]
    for i,v in enumerate(n):
        for j in range(v+1):
            L.append(j * w[i])
        W = list(set([x+y for x in W for y in L]))
        print L
        print W
        L=[0]
    print len(list(set ...
    read more

« Page 17 / 23 »

blogroll

social