Solution to problem 8 (easy)