A finite-difference algorithm for an inverse Sturm-Liouville problem