Solution to programming 3