Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #OBLICZA bf
- def get_rate(arr):
- res = arr.copy()
- for i in range(len(res)-1,-1,-1):
- if res[i] == "nan":
- res[i] = [[0,0]]
- elif res[i] != "nan" and i*2+2 >= len(res):
- res[i] = [[1,1],0]
- elif res[i] != "nan":
- l = max(res[i*2+1][0])+1
- r = max(res[i*2+2][0])+1
- res[i] = [[l,r],l-r]
- # res[i] = res[i*2+1] + 1 if res[i*2+1] >= res[i*2+2] else res[i*2+2] + 1
- for i in res:
- del i[0]
- return res
- #ZNAJDUJE NASTĘPNIK
- def find_nastepnik(arr,index):
- k = index*2+2
- flag = True
- if k * 2 + 1 < len(arr) and arr[k * 2 + 1] == "nan":
- flag = False
- while k < len(arr) and arr[k] != "nan" and flag == True:
- k = k * 2 + 1
- return k if flag == False else (k-1)//2
- #ZNAJDUJE POPRZEDNIK
- def find_poprzednik(arr,index):
- k = index * 2 + 1
- flag = True
- if k * 2 + 1 < len(arr) and arr[k * 2 + 2] == "nan":
- flag = False
- while k < len(arr) and arr[k] != "nan" and flag == True:
- k = k * 2 + 2
- return k if flag == False else (k-1)//2
- #DODAJE ELEMENT DO TABLICY
- def add_element(arr,el,index=0):
- if el == arr[index]:
- if arr[index*2+2] == "nan":
- arr[index*2+2] = el
- else:
- add_element(arr,el,index * 2 + 2)
- elif el > arr[index]:
- if arr[index*2+2] == "nan":
- arr[index*2+2] = el
- else:
- add_element(arr,el,index * 2 + 2)
- else:
- if arr[index*2+1] == "nan":
- arr[index*2+1] = el
- else:
- add_element(arr,el,index * 2 + 1)
- return arr
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement