This is a problem I\'ve had on my mind for a long time. Being the son of a teacher and a programmer, it occurred to me early on... but I still haven\'t found a solution for it.<
I'm not sure if this covers the same ground as @Stringent Software's answer (as the name is slightly different), but I have a couple of very good friends who are researching the area of Constraint Programming. Creating timetables is one application of their research.
Dr Chris Jefferson created a program called Minion that you can download from SourceForge, and is a very fast brute force constraint problem solver written in C++