Work out the best solution