Source: https://twrand.github.io/pdfs/3261hw/HW1_solutions.pdf