Algorithm for computing the moduli space of pointed Gorenstein curves with Weierstrass gap sequence \(1,2,\ldots,g-2,\lambda,2g-3\) The greedy algorithm and the Cohen-Macaulay property of rings, graphs and toric projective curves 