Skip to content

Instantly share code, notes, and snippets.

@unilecs
Created January 4, 2018 03:32
Show Gist options
  • Save unilecs/6423b1c07a43370ff671fd4fc5ad136d to your computer and use it in GitHub Desktop.
Save unilecs/6423b1c07a43370ff671fd4fc5ad136d to your computer and use it in GitHub Desktop.
Задача 58: Формула 1 (Yeldos Balgabekov)
'''
Author: Yeldos Balgabekov
Assumptions:
1. VI contains info how much the velocity improves with the corresponding modificaiton time in TI
2. the modifications could be different, not only 5 to 3 and thus, should be sorted from best to worst '''
import pandas as pd
def quickest(dist, v, vi, ti):
'''sort modifications from best to worst
where 'si' is a ration showing time investment
into velocity increase'''
v = float(v)
data = pd.DataFrame([vi, ti]).T
data.columns = 'vi', 'ti'
data['si'] = data.vi/data.ti
data = data.sort_values(by='si', ascending=False)
time_spent_for_modification = 0
''' check if the next modification is worth doing
comparing Time to Spend to for the Modification vs.
Time to Win after the modification'''
for i in data.index:
original_time = dist / v
adjusted_time = dist / (v + data.vi[i])
time_improvement = original_time - adjusted_time
time_investment = data.ti[i]
print('time_improvement: {}, time_investment: {}, Adjust: {}'
.format(time_improvement, time_investment, time_improvement > time_investment))
if time_improvement > time_investment:
v += data.vi[i]
time_spent_for_modification += data.ti[i]
return dist / v + time_spent_for_modification
if __name__ == "__main__":
dist = 100
v = 4
vi = [1, 2, 3]
ti = [2, 4, 6]
print(quickest(dist, v, vi, ti))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment