Problem 020

Problem

Description

Steps

Consider the process of stepping from integer x to integer y along integer points of the straight line. The length of each step must be non-negative and can be one bigger than, equal to, or one smaller than the length of the previous step.

What is the minimum number of steps in order to get from x to y? The length of both the first and the last step must be 1.

Input

The input is a series of number pairs x y indicating the first and last integer points. Here is an sample input:

45 48
45 49
45 50

Output

For each pair of integers, print out the minimum number of steps required to get from x to y. Here is an sample output:

3
3
4

Note

This is based on "6.6.8 Steps" in "Programming Challenges" by Skiena and Revilla.

Solution

Approach

Simply perform the steps, realizing that the optimal solution requires a symmetrical stepping pattern.

Input/Output

Source Code