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)
5 odpowiedzi
+ 4
Here you operate in a virtual environment which has its limitations. Too much overcalculation and your code goes bust :/
+ 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.
+ 1
Program it in a local machine, that way you have no time limit for a programs runtime.
0
That's server
0
Ok. I should run simplified program in this platform