You have a rectangular sheet of paper whose sides are W and H. You want to fold it several times until it becomes a rectangle whose sides are w and h.
Every fold line is parallel to a side of the rectangle, and the shape after a fold is again a rectangle. Folding a side of length L at distance x from one of its ends (0<x<L) leaves that side with the longer of the two pieces, max(x,L−x), and the other side keeps its length.
The finished rectangle may be turned around. Any orientation whose sides are w and h counts.
Write a program that computes the minimum number of folds.