ameerkat
10/28/2016 - 5:51 AM

missing_number.py

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")