An Interest In:
Web News this Week
- April 29, 2024
- April 28, 2024
- April 27, 2024
- April 26, 2024
- April 25, 2024
- April 24, 2024
- April 23, 2024
Challenge: Counting Numbers with 7s
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
Original Link: https://dev.to/peter/challenge-counting-numbers-with-7s-33c7
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To