Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 28 Online
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!
Latest Questions
ARTSMART: Art!
2 hours ago 4 Replies 3 Medals
Jasonisyours: What were the key causes of the French Revolution in 1789?
3 hours ago 2 Replies 4 Medals
PureSoulless: Why is the word "Pedophile" always censored in yt vids?
1 day ago 3 Replies 0 Medals
Jalli: What's 58x3634u00b07
20 hours ago 6 Replies 3 Medals
arriya: who wanna play roblox
1 day ago 5 Replies 1 Medal
brianagatica14: Any artist on here?
3 days ago 7 Replies 2 Medals
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!