a less functional solution to problem 1