Solution for problem 43, done using permutations and then checking each pemutation.