Solution to problem 40.
Solution to problem 42.

This solution can probably be optimized.
Solution to problem 22 and minor change to problem 44.

Fixed earlier issue with problem 22 by sorting array before calculating