solution to trinary exercise.