Problem 22 custom solution