Author: danp
Date: 03-03-04 21:53
Sounds like a homework problem ... If you have specific questions, then you should ask those (maybe on a more appropriate forum ;). I'm not sure what help you are expecting here.
Here's how I'd think about the CountNi problem: As the problem states, you want a function that takes a list and returns a number. What can you do with a list? If you look at the example functions that you must surely have, you'll see that you can look at a list as a head and a tail. The head is an integer. It's easy to tell if an integer is negative or not. The tail is list. What can be done with that? [slams fist into hand] If only we had a function that counted the negative integers in a list -- oh, wait, CountNi does that. Sounds kind of recursive don't you think? ;) The preceding case handles everything except where there is no head, i.e. the empty list. It's easy to count the negative integers in an empty list.
The second problem sounds tricky ... It seems a little underspecified to me. Are you allowed to use library modules? I'm guessing that a particular module in the standard library might be useful.
|
|