Implements problem eight of chapter one