Created
October 28, 2016 05:51
-
-
Save ameerkat/ff4fc4d776c74990e4c86e2ebf3195d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def missing_number(s_final): | |
for starting_length in range(1, (len(s_final)/2) + 1): | |
s = s_final[:] # copy | |
skipped = -1 | |
starting_number = int(s[:starting_length]) | |
plus_one = starting_number + 1 # the two valid options | |
plus_two = starting_number + 2 | |
s = s[starting_length:] | |
round_passed = True | |
while s and round_passed: | |
round_passed = False | |
if len(s) >= len(str(plus_one)): | |
next_number_one = s[:len(str(plus_one))] | |
if next_number_one == str(plus_one): | |
s = s[len(next_number_one):] | |
plus_one = int(next_number_one) + 1 | |
plus_two = int(next_number_one) + 2 | |
round_passed = True | |
elif skipped == -1 and len(s) >= len(str(plus_two)): | |
next_number_two = s[:len(str(plus_two))] | |
if next_number_two == str(plus_two): | |
s = s[len(next_number_two):] | |
skipped = int(next_number_two) - 1 | |
plus_one = int(next_number_two) + 1 | |
plus_two = int(next_number_two) + 2 | |
round_passed = True | |
if not s and skipped != -1: | |
return skipped | |
return None | |
print missing_number("9991001") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment