Problem 3: Missing Digits (100pts)
Write the recursive function missing_digits
that takes a number n
that is sorted in increasing order (for example, 12289
is valid but 15362
and 98764
are not). It returns the number of missing digits in n
. A missing digit is a number between the first and last digit of n
that is not in n
. Use recursion - the tests will fail if you use while or for loops.
def missing_digits(n):
"""Given a number n that is in sorted, increasing order,
return the number of missing digits in n. A missing digit is
a number between the first and last digit of n that is not in n.
>>> missing_digits(1248) # 3, 5, 6, 7
4
>>> missing_digits(1122) # No missing numbers
0
>>> missing_digits(123456) # No missing numbers
0
>>> missing_digits(3558) # 4, 6, 7
3
>>> missing_digits(4) # No missing numbers between 4 and 4
0
>>> from construct_check import check
>>> # ban while or for loops
>>> check(HW_SOURCE_FILE, 'missing_digits', ['While', 'For'])
True
"""
"*** YOUR CODE HERE ***"