Algorithm to solve linear equation in one variable