Sensei's Library, problem 22

Adapted from Beginner Exercise 22 · OpenContent License

All problems