The function definition below is taken from Chapter 4 and describes the general problem of finding the first occurrence of a given character in a given string.
Function: first index
Inputs: text, a string; character, a string
Preconditions: |character| = 1
Output: index, an integer
Postconditions: if character occurs in text, index is the smallest integer such that text[index] = character, otherwise index = |text|
Write a definition of a function that finds the second occurrence of any digit in a given string. If a second digit is not found, the function should indicate this by
returning the length of the string. The digits can be adjacent or separated by non-numerical characters.
Examples:
In the string 'I have 1 dog and 2 cats', the first occurrence of any digit is '1', and the second occurrence is '2', so the function would return 17. (NB: The number
returned results from counting the first position in the string, the letter 'l', as position 0, the first space as position 1, etc.).
In the string 'I have 1 dog', there is no second occurrence of any digit, so the function would return 12. In the string 'I have 10 dogs', the second occurrence of
any digit is '0', so the function would return 8.
Function:
Inputs:
Preconditions:
Output:
Postconditions: