An algorithm for computing minimal curves