Least distance algorithms for linear systems