Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 8 Online
OpenStudy (anonymous):

Hey can anyone help me on the guessing method used in pset4 problem 4. This is what I have so far http://dpaste.com/hold/528870/ .

OpenStudy (anonymous):

I did a little more but I'm still lost on guessing part. http://dpaste.com/hold/529031/

OpenStudy (anonymous):

on line 18 of your second dpaste you are multiplying the growth rate by .001 - is that what you want? at line 24: expenses = savings At lines 27 and 29 you modify expenses add a print statement after line 29 but still inside the while loop: print "expenses:", expenses what is happening to expenses? is it doing what you want it to do? For the binary search at the end (lines 25+) you want to start off with a range of expenses - maybe min_expense = 1 and max_expense = savings Those are the two extremes - your answer is between them. You want to start off half-way between the extremes - maybe call it mid_expense. Test it If mid_expense is too large then you know that the answer is somewhere between mid_expense and min_expense - those are your new extremes - set max_expense = mid_expense then calculate a new mid (half-way between the new min and max). If mid_expense is too small then you know the answer is between mid_expense and max_expense - those are your new extremes. Set min_expense = mid_expense and calculate a new mid (between the new min and max) Now it is time to loop and try it again with the new min/mid/max. put a print statement at the bottom of the loop to print min/mid/max so you can watch how they are changing and see if they are doing what you think they should do.

OpenStudy (anonymous):

Lines 25+ were guesses to try and figure it out because people weren't replying so I was trying to do it by myself but couldn't figure it out so I just posted what I had.

OpenStudy (anonymous):

egg = nestEggVariable() savings = egg[-1] dif = epsilon * 2.0 years = len(postRetireGrowthRates) guess = savings/years while dif > epsilon account = postRetirment() dif = account[-1] guess += dif/years return expenses

OpenStudy (anonymous):

think simple.

OpenStudy (anonymous):

Is that supposed to be a functional code or just something to give me an idea of how to do it?

OpenStudy (anonymous):

I got it thank you

OpenStudy (anonymous):

hmm ... i thought the intent of pset4 problem 4 was to do a write a solution using a binary search - not just get an answer.

OpenStudy (anonymous):

Wait, what do you mean?

OpenStudy (anonymous):

It does say that but i am unsure how to make a binary search work in this question. Also does not explain binary search until lecture 9 which is 2 lectures after ps4 is due.

OpenStudy (anonymous):

Sorry what is binary search I don't remember

OpenStudy (anonymous):

http://en.wikipedia.org/wiki/Binary_search#Implementations its sorta covered (the bisectional sqrt function)... but binary search is not explicitly covered until lecture 9.

OpenStudy (anonymous):

I think that is what I did? http://dpaste.com/hold/529521/

OpenStudy (anonymous):

Here's what I got: http://pastebin.com/eauphLLR

OpenStudy (anonymous):

We did the same thing pretty much.

OpenStudy (anonymous):

One of the readings for lectures 7&8 was the wikipedia entry for binary search. Binary search method/algorithm is introduced (with code) at about 37min 30sec of lecture 8 (but you should probably start watching earlier in the lecture). but pset4 was due for lecture 8 - sorry - maybe I went back and rewrote it - then again I do a lot of side reading in between lectures and take my time on the problems. here's wha I got, fwiw, http://dpaste.com/529890/. left in the print statements.

OpenStudy (anonymous):

sorry - http://dpaste.com/529892/

OpenStudy (anonymous):

Ok sorry to keep asking this but what actually is binary search is it the part where you do (min+max)/2 and see if it is to big or too small and repeat.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!