Solved exercise 1-22.\nNot completely satisfied with the implementation.