Created
August 9, 2018 13:38
-
-
Save keitheis/819f6e2d8c981ebdc2d4ee1d0fa10e5a to your computer and use it in GitHub Desktop.
This file contains 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 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