A combinatorial algorithm related to the geometry of the moduli space of pointed curves