A program to calculate a reachable matrix