Refer to assignment for description of problem.
Solution: Here are two solutions, first the one beginners are most likely to write and then one that is simpler but might not occur to anyone who hasn't yet encountered the general problem.
Refer to assignment for description of problem.
Solution: Here is one solution (not perhaps optimal and well-documented but does pass all my tests):