Advertisement
lpjakewolfskin

pisya

Jan 18th, 2022
637
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def get_result(rocket_pos, rocket_speed):
  2.     k = {i: {'pos': rocket_pos[i], 'speed': rocket_speed[i]} for i in range(len(rocket_pos))}
  3.     res = len(k.keys())
  4.     while True:
  5.         for i in k.keys():
  6.             for j in k.keys():
  7.                 if i == j:
  8.                     continue
  9.                 if k[i]['pos'] >= 1000 or k[j]['pos'] >= 1000:
  10.                     continue
  11.                 if k[i]['pos'] < 0 or k[j]['pos'] < 0:
  12.                     continue
  13.                 if k[i]['pos'] == k[j]['pos']:
  14.                     k[i]['speed'] += k[j]['speed']
  15.                     k[j]['pos'] = -1
  16.                     res -= 1
  17.         ctr = 0
  18.         for i in k.keys():
  19.             if k[i]['pos'] >= 0:
  20.                 k[i]['pos'] += k[i]['speed']
  21.             if k[i]['pos'] > 1000 or k[i]['pos'] < 0:
  22.                 ctr += 1
  23.         if ctr == len(k.keys()):
  24.             break
  25.     return res
  26.  
  27.  
  28. if __name__ == '__main__':
  29.     rocket_pos_ = [3, 10, 5]
  30.     rocket_speed_ = [1, 2, 3]
  31.  
  32.     print(get_result(rocket_pos_, rocket_speed_))
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement