http://www.cs.wisc.edu/~cs354-2/cs354/solutions/a4hw.ans.html