Solution for problem set 2 optional 1