# Challenge: Counting Numbers with 7s

April 18, 2023

## Prompt

Write a program to calculate the percentage of numbers in a given range that contain the digit 7. Your program should be able to calculate the percentages for the following ranges:

• 0-99
• 0-999
• 0-9999
• 0-99999
• etc.

The program should take a single integer input n that represents the maximum range (exclusive), i.e., the program will calculate the percentage of numbers containing a 7 in the range from 0 to n-1.

You may use any programming language of your choice. Extra imaginary bonus points for a performant approach that can handle larger and larger ranges efficiently.

## Examples

Input => Output

``````10 => 10.00%
100 => 19.00%
``````

In the first example, 1/10 numbers (10%) contain a 7 (just the number 7).

In the second example, 19/100 numbers (19%) contain a 7 (10 numbers from 70 to 79, plus 7, 17, 27, 37, 47, 57, 67, 77, 87, 97). Thus, the output is “19.00%”.

Have fun!

7️⃣ 7️⃣ 7️⃣

Cover image via Unsplash.