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

For ps4d... I'm a little confused as to exactly what program I'm supposed to write. I understand that I'm supposed to write a binary search on the post retirement income numbers but does the search need to take into account the end total (which would seem fairly useless since that wouldn't account for lost interest) or is it supposed to search each 'year' of retirement, taking into account how making choices effects interest...? I'm thinking a search needs to be performed each year, then recalculating the value assignments...

OpenStudy (anonymous):

You need to do two things, first find the total savings at the point of retirement calling your problem 2 function with the arguments salary, save, preretiregrowthrates and taking the last value of the list. Then create a binary search that takes this value. postretirementgrowthrates, and a guess for expenses, feeds it to your solution to problem 3 , and compares the result of the last value of that list to 0, then adjust your guess. The only year of retirement you need to be concerned about is the final one, as defined by the postretiregrowthrates list.

OpenStudy (anonymous):

you are searching for the value (expense) that will leave you with some minimum amount of cash at the end of your retirement (constraint) the binary search generates guesses for expense using the guess, test the cash left over against the constraint to see if the guess was too hi or too low

OpenStudy (anonymous):

right on. That's what I was getting from the HW. So I've taken the final money in retirement and used that number in a binary search looking for what expenses I could have over the length of my retirement so that final number = 0. Am I supposed to then re-run the postRetirementGrowthRate numbers with my savings-expenses (to account for loss of interest), then re-run the binary search again, etc. until I'm at the last year? That would be the most realistic way to do it but I'm not sure if it's outside of the scope of the HW problem...

OpenStudy (anonymous):

postRetirement returns a list, the last item in the list is the amount of money that is left 'after' retirement your postRetirement function should account for a yearly expense (which is the same each year) and varying interest rates. if that function is correct then all you do is feed it with a guess and then check the result for how much is left - if it was too much or too little you need to generate another guess and feed it into the function for each guess at expense the savings and growthRates arguments remain the same the only thing that changes is expenses.

OpenStudy (anonymous):

gotcha bwCA. That's what I was trying to understand, at what point I was supposed to perform the search and then when to plug it in. Now let's see how it goes... Thanks!

OpenStudy (anonymous):

Got it working. It's interesting including function modifications as part of a binary search loop. It's funny how I keep thinking I've got to break things down more, be more literal, when it seems with functions (if you set it up correctly) you can let them do all the work for you! Dear functions - I know I don't know you well but I <3 you.

OpenStudy (anonymous):

functions have an overhead cost but they can really make the code you are writing more readable, which can help if it is complicated - especially a few months down the road.

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!