implemented valid-solution? function