how do I figure out how to write an equation (and solve the problem) for algorithm?