|
Author
|
Topic: I HATE my scheme class
|
Psychotakes[NSV] Citizen Posts: 4527 Registered: Jul 1999
|
posted 09-27-2000 01:36 AM
So we're supposed to write a simple procedure to handle the following problem:"A good way to accumulate money is to save regularly. Suppose you deposit D dollars into a bank account on January 1st, and the first of the month thereafter deposit an additional S dollars each month. Suppose further that the bank pays I percent interest annually, calculated once per month, sometime other than the first. Assuming rigorous self-control on your part, in that you don't touch the money until December 31st some Y years later, you will have accumulated quite a pile, depending of course on the values of D, S, I, Y. Write a procedure SAVINGS-ESTIMATOR that, given these four input values, calculates the amount of that you would accumulate under this plan. You should assume that Y is an integer, and the rest are floating point numbers. Here is an example of how your procedure will be called: If someone were to start with $1000, with additional monthly deposits of $100/month for 18 years, assuming 6% annual interest, the call to your procedure would look like this: (savings-estimator 1000.0 100.0 6.0 18)" I know that that procedure's particular answer is 41572.1, so if I want to test mine when I'm finished I can find out if its right. Any ideas WHERE to start with this thing? I'm no good at word problems. This is the first assignment, we haven't learned anything in class yet except that xemacs and winscheme48 are a bitch to get working when they dont tell you how, heh. IP: 199.74.100.192 |
Che Guevara Citizen Posts: 1571 Registered: Feb 99
|
posted 09-27-2000 01:41 AM
Find out which chapters you were supposed to have read so far, make sure they've been read. By you, preferably. If you still dunno what to do, bitch to the teacher about his/her incompetence. In an anonymous death threat, preferably.IP: 63.194.208.5 |
Psychotakes[NSV] Citizen Posts: 4527 Registered: Jul 1999
|
posted 09-27-2000 01:42 AM
To make myself clearer, the chapters we read cover CODING and primitives and such, NOT how to solve word problems.And I want to pass this class. IP: 199.74.100.192 |
Che Guevara Citizen Posts: 1571 Registered: Feb 99
|
posted 09-27-2000 01:45 AM
Hardly a word problem. Just an accumulative number that goes up (and luckily, never ever down (of course untill Dec. 1 of Y where it's all blown on hookers and crack)). I do remember that shit somewhat. I hated math to begin with, so... fuck it all. Drop the class like I did :PIP: 63.194.208.5 |
Psychotakes[NSV] Citizen Posts: 4527 Registered: Jul 1999
|
posted 09-27-2000 01:46 AM
I cant drop it, my parents would kill me and scheme is the foundation class for all CS classes in the department.Mmmm factorial easiness=good (define (factorial n) (factorial-helper n 1)) (define (factorial-helper n result) (if (not(integer? n)) #f (if (negative? n) #f (if (= n 0) result (factorial-helper (- n 1) (* result n)))))) Edit: Formatting lost in post
[This message has been edited by Psychotakes[NSV] (edited 09-27-2000).] IP: 199.74.100.192 |
Che Guevara Citizen Posts: 1571 Registered: Feb 99
|
posted 09-27-2000 01:49 AM
Does all that mean that I've helped you?  IP: 63.194.208.5 |
Psychotakes[NSV] Citizen Posts: 4527 Registered: Jul 1999
|
posted 09-27-2000 01:53 AM
You helped me as much as you helped that tree.IP: 199.74.100.192 |
Che Guevara Citizen Posts: 1571 Registered: Feb 99
|
posted 09-27-2000 01:55 AM
In which case you're as fucked as my fist was. Oh well, it'll all work out in the end.IP: 63.194.208.5 |
Lt.Hawkins Citizen Posts: 5677 Registered: Mar 99
|
posted 09-27-2000 02:06 AM
code:
(define (savings-estimator d s i y) (savings-estimator-month d s (/ i 12) (* y 12))) (define (savings-estimator-month d s i m) (if (= m 0) d (savings-estimator-month (+ d s (* d (/ i 100))) s i (- m 1))))
its tail-recursive. first, turn it into something nice and easy. instead of dealing with annual interest and years past and month contributions, change it into monthl-based stuff. so i made a helper fxn called estimate-interest-month that works in months, and just called that from the regular estimate-interest. (divide the interest rate by 12, and multiply years by 12 to get number of months. pass everyting else the same. then the interesting stuff each month, you'll end up with the amount you start with, plus interest for that month, plus monthly contribution. keep doing that, until you have no more months left (- m 1) [This message has been edited by Lt.Hawkins (edited 09-27-2000).] [This message has been edited by Lt.Hawkins (edited 09-27-2000).] IP: 24.188.200.148 |
Psychotakes[NSV] Citizen Posts: 4527 Registered: Jul 1999
|
posted 09-27-2000 02:20 AM
For those wondering, it works. Hawkins is a god. I need some way to thank him.edit: its almost workin perfectly, will tweak  Lt: If you ever need to abuse processing power or bandwidth (or would like a northwestern email account) I'll try to hook you up. [This message has been edited by Psychotakes[NSV] (edited 09-27-2000).] IP: 199.74.100.192 |
Lt.Hawkins Citizen Posts: 5677 Registered: Mar 99
|
posted 09-27-2000 02:26 AM
wimin, bacon or Visa only, please...i'd say put me in your sig to boost my ego, but you're like me- you don't post your sig. so i'll have to settle for the wimin. IP: 24.188.200.148 |
Lt.Hawkins Citizen Posts: 5677 Registered: Mar 99
|
posted 09-27-2000 02:32 AM
don't forget to make floating point whatever needs to be floats.(actually, many times, so long as you make one of the variables a float and its used in calculations with all the others, then it'll still come out correct. good ngith. i'm zonked from all those women you sent over. please send more IP: 24.188.200.148 |
]EA[Markov Citizen Posts: 696 Registered: Feb 99
|
posted 09-27-2000 04:14 AM
you get assigned lame problemsIP: 128.113.151.169 |
[20ID]God Incarnate Citizen Posts: 305 Registered: May 99
|
posted 09-27-2000 11:06 AM
We have problems like this in my engineering economics class. There's supposed to be a leet formula for those problems. I really wish I payed attention to last night's class. lolIP: 24.156.27.149 |