An Algorithm for Least Squares