[H-GEN] Programing

Martin Pool mbp at linuxcare.com.au
Sun Jul 30 21:36:06 EDT 2000


On Mon, Jul 31, 2000 at 11:16:36AM +1000, Andrae Muys wrote:

>   (If your language has a sort function, don't use it for this one :)
> Read all the numbers from a file (unlimited but assume will fit in
> memory) sort them and write to another file.

OK, this last one is a good example of the different things that C and
Python will teach you.

In Python, it's very nearly a one-liner and if the sort() list method
was allowed then it would be.  Nevertheless it's still a useful
exercise in thinking about algorithms systematically, and so on.

In C it's way more complicated: having an unlimited number of entries
probably implies dynamic allocation, which is a very large kettle of
fish for the beginner, but a powerful idea.

Will you sort the numbers as you read them in, in an intermediate
stage, or as you write them out?  What if there are duplicates, or
non-numbers?  What if there are after all more than will fit in
memory?  (How many will fit in memory anyhow?  What is the limit of
memory?)  Are the numbers required to be integers, are they positive,
and how much precision is required?  Handling arbitrary length
197823908174987123471234987 numbers is also trivial in Python but more
challenging in C.  All these questions go towards the requirements and
analysis skills necessary to solve practical problems.

`The Practice of Programming' is a simply superb book for working
through this kind of topic.  For about $50 it will teach you more than
some six month courses.

Happy hacking!
-- 
Martin Pool, Linuxcare, Inc.
+61 2 6262 8990
mbp at linuxcare.com, http://www.linuxcare.com/
Linuxcare. Support for the revolution.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
URL: <http://lists.humbug.org.au/pipermail/general/attachments/20000731/4c87f409/attachment.sig>


More information about the General mailing list