fear.net forums
  Just some BS
  I HATE my scheme class

Post New Topic  Post A Reply
profile | register | preferences | faq | search

UBBFriend: Email This Page to Someone! next newest topic | next oldest topic
Author Topic:   I HATE my scheme class
Psychotakes[NSV]
Citizen

Posts: 4527
Registered: Jul 1999

posted 09-27-2000 01:36 AM     Click Here to See the Profile for Psychotakes[NSV]   Click Here to Email Psychotakes[NSV]     send a private message to Psychotakes[NSV]   Edit/Delete Message   Reply w/Quote
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     Click Here to See the Profile for Che Guevara   Click Here to Email Che Guevara     send a private message to Che Guevara   Edit/Delete Message   Reply w/Quote
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     Click Here to See the Profile for Psychotakes[NSV]   Click Here to Email Psychotakes[NSV]     send a private message to Psychotakes[NSV]   Edit/Delete Message   Reply w/Quote
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     Click Here to See the Profile for Che Guevara   Click Here to Email Che Guevara     send a private message to Che Guevara   Edit/Delete Message   Reply w/Quote
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 :P

IP: 63.194.208.5

Psychotakes[NSV]
Citizen

Posts: 4527
Registered: Jul 1999

posted 09-27-2000 01:46 AM     Click Here to See the Profile for Psychotakes[NSV]   Click Here to Email Psychotakes[NSV]     send a private message to Psychotakes[NSV]   Edit/Delete Message   Reply w/Quote
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     Click Here to See the Profile for Che Guevara   Click Here to Email Che Guevara     send a private message to Che Guevara   Edit/Delete Message   Reply w/Quote
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     Click Here to See the Profile for Psychotakes[NSV]   Click Here to Email Psychotakes[NSV]     send a private message to Psychotakes[NSV]   Edit/Delete Message   Reply w/Quote
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     Click Here to See the Profile for Che Guevara   Click Here to Email Che Guevara     send a private message to Che Guevara   Edit/Delete Message   Reply w/Quote
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     Click Here to See the Profile for Lt.Hawkins   Click Here to Email Lt.Hawkins     send a private message to Lt.Hawkins   Edit/Delete Message   Reply w/Quote
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     Click Here to See the Profile for Psychotakes[NSV]   Click Here to Email Psychotakes[NSV]     send a private message to Psychotakes[NSV]   Edit/Delete Message   Reply w/Quote
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     Click Here to See the Profile for Lt.Hawkins   Click Here to Email Lt.Hawkins     send a private message to Lt.Hawkins   Edit/Delete Message   Reply w/Quote
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     Click Here to See the Profile for Lt.Hawkins   Click Here to Email Lt.Hawkins     send a private message to Lt.Hawkins   Edit/Delete Message   Reply w/Quote
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     Click Here to See the Profile for ]EA[Markov   Click Here to Email ]EA[Markov     send a private message to ]EA[Markov   Edit/Delete Message   Reply w/Quote
you get assigned lame problems

IP: 128.113.151.169

[20ID]God Incarnate
Citizen

Posts: 305
Registered: May 99

posted 09-27-2000 11:06 AM     Click Here to See the Profile for [20ID]God Incarnate   Click Here to Email [20ID]God Incarnate     send a private message to [20ID]God Incarnate   Edit/Delete Message   Reply w/Quote
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. lol

IP: 24.156.27.149

All times are ET (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | fear


Ultimate Bulletin Board 5.45b