a working homework answer

by-the-book, unoptimized answer