1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| list1 = [ 1,4, 5, 11, 12, 19, 27, 30, 34, 200 ] list2 = [ 1, 4, 13, 19, 22, 31, 34, 92, 201, 300 ]
def sort(array): if len(array) < 2: return array else: standard = array[0] i = 1 less = [] big = [] while i != 20: if array[i] <= standard: less.append(array[i]) else: big.append(array[i]) i = i+1
return sort(less) + [standard] + sort(big) def sort_new_array(a, b): list_new = list1 + list2 sort(list_new) return list_new def is_odd(x): if x % 2 == 0: return False else: return True
def split_odd_even(array): odd_list = [] even_list = [] i = 0 while i != 20: if is_odd(array[i]): odd_list.append(array[i]) else: even_list.append(array[i]) i = i+1 return odd_list, even_list
def count_same_number(list1, list2): i = 0 count = 0 while i != 10: j = 0 while j != 10: if list1[i] == list2[j]: count = count + 1 break j = j + 1 i = i+1 return count print(count_same_number(list1, list2))
def shift_list1(f, n): i = 0 new_list = [0] * len(f) while i != len(f)-1: new_list[(i+n) % len(f)] = f[i] i = i + 1 return new_list
def is_ascending(array): i = 0 flag = True while i < len(array)-1: if array[i] <= array[i+1]: i = i+1 else: flag = False i = len(array)-1
return flag
def check_ascending_after_roted(array): n = 0 flag = False while n != 30 and not flag : if is_ascending(shift_list1(array,n)): flag = True else: n = n+1 return flag
PYTHON
|