+0  
 
0
69
1
avatar

If you randomly drew a number between 1 and 100,000, what is the probability that its digits sum up to 22? Thanks for any help.

 Aug 4, 2020
 #1
avatar
0

I don't know how to solve it mathematically, but I can write a short computer code to find out how many numbers are there between 1 and 100,000 whose digits sum up to 22. Here is the code:

 

%%time;# Function to return the  sum of digits of x between L and R # 
def sumOfDigits(x): 
    sum = 0
    while x != 0: 
        sum += x % 10
        x = x//10
    return sum
  # Function to return the count 
# of required numbers 
def countNumbers(L, R): 
    count = 0
    for i in range(L, R + 1): 
  # ENTER SUM OF DIGITS HERE # 
     if sumOfDigits(i)==22: 
            count += 1
    return count 
  L =1; R = 99999
print("Total = ", f"{countNumbers(L, R):,d}") 

 

OUTPUT =6,000 [Exactly!]. Therefore, the probability is: 6,000 / 100,000 ==6%.

 Aug 4, 2020

20 Online Users

avatar
avatar