Implementing our algorithm for a single variable