How to solve Time limit exceeded problem? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to solve Time limit exceeded problem?

Here is my program using bisection method total_cost=1000000 S=float(150000) G=1.07 down_payment=float(total_cost)*0.25 r=(1+0.04/12) current_saving=0 low=0 high=1 x=(low+high)/2.0 eplison=100 months=0 while abs(current_saving-down_payment)>eplison: while months <=36: current_saving=current_saving*r if months%6-1==0 and months>=6: S=S*G current_saving=current_saving+S*x/12.0 months+=1 if current_saving-down_payment>0 : high=x x=(low+high)/2.0 if current_saving-down_payment<0 : low=x x=(low+high)/2.0 print('Best portion for saving within 36months is',x) print(current_saving)

30th May 2017, 3:12 PM
hahaha
hahaha - avatar
5 Answers
+ 4
Here you operate in a virtual environment which has its limitations. Too much overcalculation and your code goes bust :/
30th May 2017, 3:28 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 3
I checked your outer 'while' with: print( abs( current_saving - down_payment), eplison) ctr+=1 if (ctr>15): break The end conditions never change. It looks like it will run forever, anywhere.
30th May 2017, 3:47 PM
Kirk Schafer
Kirk Schafer - avatar
+ 1
Program it in a local machine, that way you have no time limit for a programs runtime.
30th May 2017, 3:21 PM
Madera Oxidada
Madera Oxidada - avatar
0
That's server
30th May 2017, 3:17 PM
Harsh
Harsh - avatar
0
Ok. I should run simplified program in this platform
30th May 2017, 3:41 PM
hahaha
hahaha - avatar