L = "caayyhheehhbbbhhjhhyyaac"
start, length = 0, 0
for i in range(1,len(L)-1):
if L[i] == L[i+1]:
s = min(len(L[:i+1]),len(L[i+1:]))
a, b = 1, 1
while a < s:
if L[i-a] == L[i+1+a]: # to the left 1 pace ...- read more
53.The arrangement of the god
read more# 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 ...
52.Factor sum of squares
read more# -*- 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 ...
51.Descending order
read moreL = [2, 8, 3, 50] print sorted(L)[::-1] print [x for x in reversed(sorted(L))]
50.Py throw the shot put
read moreimport math print '%.3f'%(a/math.tan(b))
49.hexadecimal conversion
read morea=184 b=16 if a<0: a=-a flag='-' else: flag='' res=[] d={0:'0',1:'1',2:'2',3:'3',4:'4',5:'5',6:'6',7:'7',8:'8',9:'9',10:'A',11:'B',12:'C',13:'D',14:'E',15:'F'} while a>0: res ...
48.Weight problems 2
read morew=[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 ...
47.Yang hui triangle
read moren=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 ...
46.Take stones game
read more# (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 ...
45.Weight problems
read morew=[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 ...