Add iterative solution to problem #18