L = [2, 8, 3, 50]
print sorted(L)[::-1]
print [x for x in reversed(sorted(L))]
- read more
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 ...
44.super stairs
read moredef stairs(n): return (n==1 or n==2) and 1 or (stairs(n-1)+stairs(n-2)) print(stairs(3))
43.The Fibonacci sequence
read morea=[1,1] for i in range(2,n): a.append(a[i-2]+a[i-1]) print a[n-1]%20132013
42.Splitting the prime Numbers sum
read moren=10 def isPrime(n): if n <= 1: return False for i in range(2, n): if n % i == 0: return False return True count = 0 for i in range(2,n): if isPrime(i) and isPrime(n-i): count += 1 print count/2