Simplify Problem 18 and remove immutability