Advertisement
Peaser

problems

May 8th, 2015
564
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. import itertools, random
  2.  
  3. de = [1, 5, 7, 2, 8]
  4.  
  5. def sum1(l): # for
  6.     k = 0
  7.     for i in l:
  8.         k += i
  9.     return k
  10.  
  11. def sum2(l): #while
  12.     final = 0
  13.     incr = 0
  14.     while incr < len(l):
  15.         final += l[incr]
  16.         incr += 1
  17.     return final
  18.  
  19. def sum3(l): #recursion
  20.    if len(l) == 1:
  21.         return l[0]
  22.    else:
  23.         return l[0] + sum3(l[1:])
  24.  
  25. def altern(l1, l2):
  26.     return list(itertools.chain.from_iterable(zip(l1, l2)))
  27.  
  28. def fib():
  29.     a = []
  30.     for i_ in [0, 1, 1]: a.append(i_)
  31.     for _ in range(3, 100):
  32.         a.append(sum(a[-2:]))
  33.     return a
  34.  
  35.  
  36. def arrLarg(l):
  37.     iterations = len(l)**4
  38.     b = []
  39.     for i in range(iterations):
  40.         k = l[:]
  41.         random.shuffle(k)
  42.         k = int(''.join([str(i) for i in k]))
  43.         b.append(k)
  44.     b = list(set(b))
  45.     b.sort(reverse=True)
  46.     return b[0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement