Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from zipfile import ZipFile
- import random
- # Minimal descending sequence.
- def mds(lines):
- m = 0
- n = len(lines)
- lds = [1] * n
- for i in range(n):
- for j in range(i):
- if lines[i] < lines[j] and lds[i] < lds[j] + 1:
- lds[i] = lds[j] + 1
- for i in range(n):
- if m < lds[i]:
- m = lds[i]
- # print("minimal descending sequence="+str(m))
- return m
- def clean_tables(lines):
- for i in range(1, len(lines)):
- lines[i] = int(lines[i][:-1])
- lines.pop(0)
- return lines
- def computerounds(lines, a, b):
- roundnumber = 1
- for i in range(a, b):
- if lines[i][1] > lines[i + 1][1]:
- roundnumber += 1
- return roundnumber
- # Python code to sort the lists using the second element of sublists
- # Inplace way to sort, use of third variable
- def Sort(sub_li):
- l = len(sub_li)
- for i in range(0, l):
- for j in range(0, l - i - 1):
- if (sub_li[j][0] > sub_li[j + 1][0]):
- tempo = sub_li[j]
- sub_li[j] = sub_li[j + 1]
- sub_li[j + 1] = tempo
- return sub_li
- def swap(a, i, j):
- tmp1 = a[j]
- a[j] = a[i]
- a[i] = tmp1
- a[i][0] = i + 1
- a[j][0] = j + 1
- return a
- def tauluja(lines: object) -> object:
- return len(lines)
- def kierroksia(lines):
- a = []
- for i in range(len(lines)):
- a.append([lines[i], i])
- a = Sort(a)
- k = 1
- for i in range(len(a) - 1):
- if a[i][1] < a[i + 1][1]:
- k += 1
- smallestround = len(a)
- for i in range(len(a) - 1):
- for j in range(i + 1, len(a)):
- if a[i][1] > a[j][1]:
- a = swap(a, i, j)
- tmp = computerounds(a, 0, len(lines) - 1)
- if tmp < smallestround:
- smallestround = tmp
- a = swap(a, i, j)
- return smallestround
- if __name__ == '__main__':
- lines = [6, 1, 4, 10, 7, 2, 3, 9, 5, 8]
- numberoftables = tauluja(lines)
- smallestround = kierroksia(lines)
- numberofswaps = mds(lines)
- print(numberoftables, smallestround, numberofswaps)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement