https://courses.grainger.illinois.edu/cs466/sp2020/assignments/PS4_sol.pdf