This version uses sets instead of dicts,... although in the matrix part
I am not sure about the efficiency of sets versus lists. The latter is
beacause althought sets are hashables, . . . how good they are if we
have thousands of elements?