Given a positive integer N with at least two digits, we can define magic(N) as follows:
Write N as a string of decimal digits. Now, for each two consecutive digits, compute their difference
(a non-negative number less than ten), and write it down. In this way you'll obtain a new number,
possibly with leading zeroes. Drop unnecessary leading zeroes if there are any.
For example, magic(5913)=482, magic(1198)=081=81, and magic(666)=00=0.
For any number N the sequence: N, magic(N), magic(magic(N)), ... will sooner or later terminate with a single-digit number.
This final value is called the magic fingerprint of N.
For example, for N=5913 we get the sequence: 5913, 482, 46, 2. Therefore the magic fingerprint of 5913 is 2.
There are not too many numbers with the magic fingerprint seven (7). These numbers are considered lucky.
Write a method that will compute the count of lucky numbers between A and B, inclusive.
|