Checks latin square, written in Prolog