http://www.cs.uiuc.edu/class/fa08/cs373/Problem_Sets/hw8-sol.pdf