Problem 40 solution
Problem 26 solution