TopCoder problem "NoEights" used in SRM 355 (Division II Level Two)



Problem Statement

    

Cyclists don't like the number eight because it symbolizes a broken wheel. Recently, the mayor of Moscow decided to force all cyclists to get an identification number. Vasya was presented with the following choice: he can choose any number between low and high, inclusive. He wants his number to contain as few eights as possible. Return the minimal possible number of eights he can have in his number.

 

Definition

    
Class:NoEights
Method:smallestAmount
Parameters:int, int
Returns:int
Method signature:int smallestAmount(int low, int high)
(be sure your method is public)
    
 

Constraints

-low will be between 1 and 2000000000, inclusive.
-high will be between low and 2000000000, inclusive.
 

Examples

0)
    
1
10
Returns: 0
Any number except 8 will do.
1)
    
88
88
Returns: 2
The only possible number is 88.
2)
    
800
899
Returns: 1
The first 8 is unavoidable.
3)
    
8808
8880
Returns: 2

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=7759

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10712&pm=7759

Writer:

Petr

Testers:

PabloGilberto , brett1479 , Olexiy , marian

Problem categories:

Simple Math