The challenge is to identify the missing number in a string of undelimited integers.
You are given a string of digits (valid input will match the regular expression
^[1-9][0-9]+$). The string represents a sequence of integers. For example,
1234567891011. All numbers in the sequence are in the range from
The sequence is a series of numbers where each number is one greater than its predecessor. However, this sequence may contain one and only one missing number from the sequence. It is possible that a given string also contains no missing numbers from the sequence. The string will always contain at least two numbers from the sequence.
The code must output or return the missing value, or
0 (this is a
0 - not a falsy value) in the event that the no missing values were found.
The following are valid inputs and their output/return:
input output actual sequence (for refrence) 123467 5 1 2 3 4 _ 6 7 911 10 9 __ 11 123125126 124 123 ___ 125 126 8632456863245786324598632460 8632458 8632456 8632457 _______ 8632459 8632460 123 0 1 2 3 8632456863245786324588632459 0 8632456 8632457 8632458 8632459
While all of this is described as a 'string' as input, if the language is capable of handling arbitrarily large numbers (
mathematica, I'm looking at you two) the input may be an arbitrarily large number instead of a string if that makes the code easier.
For reference, this was inspired by the Programmers.SE question: Find missing number in sequence in string