Unoptimized solution for Problem 23