Skip to content

Instantly share code, notes, and snippets.

@keitheis
Created August 9, 2018 13:38
Show Gist options
  • Save keitheis/819f6e2d8c981ebdc2d4ee1d0fa10e5a to your computer and use it in GitHub Desktop.
Save keitheis/819f6e2d8c981ebdc2d4ee1d0fa10e5a to your computer and use it in GitHub Desktop.
def print_missing_number(nums):
should_be = 0
current = 0
for i, n in enumerate(nums, 1):
current += n
should_be += i
print(f"should_be: {should_be}, current: {current}")
print(should_be - current)
def main():
import random
total_length = random.randint(2, 9)
takeout = random.randint(0, total_length)
nums = set(n for n in range(total_length))
print(f"Takeout {takeout} from {nums}")
nums.remove(takeout)
print(f"nums {nums}")
print_missing_number(nums)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment