The second problem was more challenging, and many nice solutions were submitted. So let's begin with the easy one first. Ordering Fractions Consider the set of all reduced rational numbers between 0 and 1 with denominators less than or equal to n . To unlock a combination lock you must rotate a dial alternately right and left through a sequence of positive numbers. Express each combination by giving the first and last number in the combination.
Lets begin with a mathematical analysis of the problem.
The problem reduces to finding all solutions to the previous equation with integer solutions. Now apply this function to all possible starting integers k . Thus, he replaces the Range argument with the Divisors of 2 m . The very fastest implementation of this idea is the following solution. Here is how the three solutions compare in speed.